开发者

ASP.NET MVC3: model binding with hidden field

开发者 https://www.devze.com 2023-04-09 17:19 出处:网络
Here\'s the view @using (Html.BeginForm(\"Deleted\", \"Location\")) { Html.Hidden(\"LocationID\", Model.LocationID );

Here's the view

@using (Html.BeginForm("Deleted", "Location"))
{
    Html.Hidden("LocationID", Model.LocationID );

    <input type = "submit" value = "Delete" />
}

And here's the method that's supposed to receive the data.

public ActionResult Deleted(int LocationID)
{
        //Do something with Loca开发者_StackOverflow中文版tionID
        return View();
}

When I run the code, LocationID is always null. Am I missing something?

Thanks for helping


Calling Html.Hidden returns an IHtmlString containing a hidden field.
However, you aren't doing anything with the returned string.

You need to render the string to the page using an @.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号