Learning notes 24_MVC data interaction before and after

Source: Internet
Author: User

* The most common way of interacting, within the action method in Contoller

Public ActionResult Index ()

{

viewdata["Key"] =value;

Return View ();

}

* The front page of the action, in the foreground of the index.aspx, you can use <%=viewdata["Key"]%>

* The method that executes this action is the first to be executed whenever an action is requested.

* In action, you can return a page that uses a different action to the user, such as:

Public ActionResult Index (0

{

viewdata["Key"] = value;

Return View ("Index2");//If the argument is empty, then the index is found by default

}

* In action, you can return Content ("OK") in addition to return View (); , then it is equivalent to Response.Write ("OK"); Respone.end ();

When you use return Content (JSON), it is equivalent to a generic handler, which is not necessarily the output view in the action anyway.

* In action, the public ActionResult myaction (string id,string Pwd) can be used in addition to the non-parametric action method;

The formal parameter names here must be identical to the parameter names submitted by the form, which is matched when IIS runs the page life cycle by reflecting the Controller's action method.

* In action, in addition to the above parameters, you can also encapsulate id,pwd in a custom User class, the property name must be consistent with the form parameter name, such as public actionresult myaction (user user);

public class User

{

public string Id{get;set;}

Pulic string Pwd{get;set;}

}

Learning notes 24_MVC data interaction before and after

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.