How to use hidden field values from view to controller in asp.net mvc 3

前端 未结 3 1541
滥情空心
滥情空心 2021-02-08 03:38

I have to pass hidden filed values to controller action. So I have tried in the following way, but I am getting null values.

I have tried both methods i.e formcollection

3条回答
  •  盖世英雄少女心
    2021-02-08 03:59

    if your hidden value is static.Than try this

    View

    @using (Html.BeginForm(new { id = "postform" }))
    {
    
    
     @Html.HiddenFor(m=>m.hiddevalue)
        
        
    
        
    }
    

    Controller

    [HttpPost]
    public ActionResult MapIcon(Hidden hidden, string hidden1, string hidden2)
    {
        var hiddenvalue = hidden.hiddevalue;
        var hiddenvalue1 = hidden1;
        var hiddenvalue2 = hidden2;
        var value=hidden.hiddevalue;//null
        FormCollection col = new FormCollection();
        var value = col["hidden1"];
      //  string value = mycontroler.ControlName;
    
        return View(hidden);
    }
    

    Script

     $(document).ready(function () {
    
     $('#hiddevalue').val("Jaimin");
    
    });
    

提交回复
热议问题