ArticleDirectory
- Change bindinghelperextensions. updatefrom to updatemodel
-
Download: http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx? Releaseid = 16775
Article 1: Asp.net MVC codeplex preview 5 new features of Helper
Change bindinghelperextensions. updatefrom to updatemodel Usage (Disadvantage: If a field in mymodel does not exist in the form, an error is reported)
VaR x = New Mymodel ();
This . Tryupdatemodel (x, request. Form. allkeys );
Or (Disadvantage: writing one by one is too troublesome)
VaR x= NewMymodel ();
This. Tryupdatemodel (X,New[] {"Idx","Name"});
Advantage: If you define htmlhelper. validationmessage, it will be automatically empty for you. For details, see the previous article.
Of course, you can alsoThis. Tryupdatemodel (X,New[] {"Idx","Name"}, "Account ");This method is used to obtain different models.
AboveTryupdatemodel returns whether the bound bool value is successful. If it is correct, you can useUpdatemodel
Action Array parameters are provided.
View:
<% Using (html. Form ( " Home " , " Save " , Formmethod. Post )){ %>
<% = Html. checkbox ( " Like " ) %>
<% = Html. checkbox ( " Like " ) %>
<% = Html. checkbox ( " Like " ) %>
<% = Html. checkbox ( " Like " ) %>
<% = Html. submitbutton () %>
<% } %>
Action:
Public Actionresult save ( String [] Like)
{
Viewdata [ " Message " ] = String . Join ( "" , Like );
Return View ( " Index " );
}
In this way, you can obtainLikeOf
Acceptverbs Filter
This filter allows us to define the action access method.
[Acceptverbs ("Post")]
PublicActionresult save () // only post can be accessed
Or
[Acceptverbs ("Post","Get")] // Post or get can be accessed, but cannot be accessed in other ways
PublicActionresult save ()
Actionname Filter
Define its actionname for a method
As defined in homecontroller
[Actionname ( " Myaction " )]
Public Actionresult save ()
{
Return View ( " Index " );
}
/Home/save cannot be accessed
/Home/myaction is required for access.