Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add hidden field in form element in masterpage

I want to add hidden field to every view i have through jquery or javascript. But i want that code to be in MasterPage.Master so i write code at one place and it adds on every view i have. Can i do this if yes then how? Im using asp.net mvc 2

like image 936
Fraz Sundal Avatar asked Dec 03 '22 03:12

Fraz Sundal


1 Answers

In your master:

$(function() {
    $('body').append(
        $('<input/>')
            .attr('type', 'hidden')
            .attr('name', 'foo')
            .val('some value')
    );
});

or replace $('body') with some other selector to a placeholder you've put somewhere in your master page if you want this hidden field to be inserted in some specific position. You could also insert it into existing <form> by giving them some id or class (if you have more of them on the same page and you wanted to insert this hidden field in each form).

like image 146
Darin Dimitrov Avatar answered Dec 26 '22 03:12

Darin Dimitrov