Tuesday, January 18, 2011

ASP.NET MVC 2 Strongly Typed Html Helpers

using Strongly Typed Html Helpers will map the model to the view and it will help to have compile time checking of the views.

in views instead of using
<%=Html.TextBox("username", Model.UserName)%>

you can use

<%= Html.TextBoxFor( m => m.UserName)%>

in controller:

public ActionResult LogOn(string userName, string password)

use

public ActionResult LogOn(LoginViewModel loginviewModel)

moreover you dont need to use ValueProvider["UserName"].AttemptedValue to access Html value and you can use model directly.

and for adding attribute
<%= Html.TextBoxFor(model => model.UserName , new { @calss="SingleTextBox" }) %>

No comments:

Post a Comment