Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone!

Can you help me and Guide me on how to
Create hidden field and use to pass value on Controller
Thanks in Advanced
Posted
Updated 22-Jun-16 19:19pm

Hidden fields can create in view, but you can't access them in the controller directly, so you need to pass them as a parameter from client side

Sample:

XML
<input type="hidden" id="txt1" value="@objPI.Id" />
                       <input type="hidden" id="txt1" value="@objPI.Version" />
                       <input type="hidden" id="txt2" value="@objPI.FileLocationId" />


Now these values can be passed to controller as

C#
function VP_GetDesign() {
    try {

        VP_ShowLoading("Show");
        //debugger;
        var vP1 = jQuery.trim(document.getElementById("txt1").value);
        var vP2 = jQuery.trim(document.getElementById("txt2").value);
       

        var d = {
            vP1: vP1,
            vP2: vP2,
            
        }


        AjaxPost('/ViewPlace/GetDesign', d, 'VP_GetDesign_CallBack', 'VP_AjaxError');     // your post method 
    }
    catch (err) {
        VP_ShowLoading("Hide");
        alert(err);
    }
}


The controller code look's like this
SQL
public ActionResult GetDesign(String vP1, String vP2)
       {
           try
           {
               //vP1=version; vP2=filelocation
           }
         catch(Exception ex)
         {
       throw ex;
         }
       }


Thanks
SP
 
Share this answer
 
v2
Check whether hidden field is in form element.
 
Share this answer
 
Here is very simple solution for that.
<div style="padding-left:20px" class="pull-left">
@{
	if (TempData["BasketTrnId"] != null)
	{
	    var BasketTrnId = TempData["BasketTrnId"].ToString();
	    <input type="hidden" id="BasketRefNo" value="@BasketTrnId" data-bind="text: hiddnBasketRefNumber"/>
	}
	else
	{
	   <input type="hidden" id="BasketRefNo" value="" data-bind="text: hiddnBasketRefNumber" />
	}
}
</div>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900