post string to controller asp.net mvc

时间:2016-04-21 21:59:48

标签: c# asp.net-mvc

//its in ajax success
document.getElementById('koeff').innerHTML = elements.total;//type string

Posting form:

@using (Html.BeginForm("Index", "Power", FormMethod.Post))
{
        <p>Sum:  <span id="koeff" name="mult"></span></p>
      //other code with submit button
}

Controller:

public ActionResult Index(string mult)//  mult null why?
{
}

In controller mult always null, why?

1 个答案:

答案 0 :(得分:1)

This will do it:

@using (Html.BeginForm("Index", "Power", FormMethod.Post))
{
        <input type="hidden" id="koeff" name="mult" />
      //other code with submit button
       <p>Sum: <span>@ViewBag.Mult</span></p>
}

You can display sum as a label or span if you need user to see it on the page, but to post, it must be an input. In my case it's hidden input, but you can have test or any other input.