asp.net mvc - Handling hidden field in multiple forms in Mvc 4.0 -
i having multiple forms in 1 page , page inherits 1 single model.every form submission requires common value. so, common value stored in hidden field. hidden field kept global i.e outside of forms problem whenever submit form, hidden field coming empty.the hidden field @html.hiddenfieldfor(m=>m.fkid)
, fkid of string type proprty in model i.e public string fkid{get;set;}
.can please guide me how handle situation. if keep hidden field in 1 of forms , coming in controller form submission have kept it. want property set once , can use in form submissions.please me. how can sort out problem
some related code
<div id="tabs"> <ul> <li><a href="#tabs-1">nunc tincidunt</a></li> <li><a href="#tabs-2">proin dolor</a></li> <li><a href="#tabs-3">aenean lacinia</a></li> </ul> <div id="tabs-1"> @using (ajax.beginform("evaluation","savetab1"{new ajaxoptions { onsucess= "displaymessage" })) { @html.hiddenfieldfor(m=>m.fkid) <input type="submit" id="btntab1" value="submit" onclick="checkuser();"/> } </div> <div id="tabs-2"> @using (ajax.beginform("evaluation","savetab2"{new ajaxoptions { onsucess= "displaymessage" })) { @html.hiddenfieldfor(m=>m.fkid) <input type="submit" id="btntab2" value="submit" /> } </div> <div id="tabs-3"> @using (ajax.beginform("evaluation","savetab3"{new ajaxoptions { onsucess= "displaymessage" })) { @html.hiddenfieldfor(m=>m.fkid) <input type="submit" id="btntab3" value="submit" /> } </div> </div> <script type="text/javascript"> function displaymessage(json) { alert( $("#fkid").val(json.hdn)); // , alert showing value $("#fkid").val(json.hdn); } </script>
in controller have:
public actionresult savetab1(model obj) { tbl ob =new tbl(); ob.fkid=obj.fkid; // after saving, return return json(new{hdn=obj.fkid}) } public actionresult savetab2(model obj) { tbl ob =new tbl(); ob.fkid=obj.fkid; //after saving, return return json(new{hdn=obj.fkid}) }
similar tab three, unfortunately hidden filed comes first form submit. return value view json , again set hidden field property comes null second form.please help
first of all, view not inherit model, strongly-typed type of model. these 2 different.
but, answer question, there's no such thing global hidden field. fields not variables. if want field posted controller, need put inside form. if have multiple forms in view, you'll have put same hidden field inside forms. so, need put @html.hiddenfor(m => m.fkid)
inside forms in view.
update: way, it's not html.hiddenfieldfor
, it's html.hiddenfor
.
Comments
Post a Comment