Asp.net MVC codeplex preview 5 new features of Controller & Filter

Source: Internet
Author: User
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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.