Tuesday 11 August 2015

Hidden Field & QueryString

Lets say you want to pass ID parameter to the controller. You can do it in 2 ways:

Via QueryString:

<form method="post" action="@Url.Action("DoSomething", "Customer", new { id = Model.ID })">
</form>

Or Via Hidden Fields:

<form method="post" action="@Url.Action("DoSomething", "Customer")">
    <input type="hidden" value="@Model.ID" />
</form>

Either way its fine, browser will add any form elements to the querystring automatically, so difference in performance as well.


No comments:

Post a Comment