The arguments in MVC and get in view

Source: Internet
Author: User

The first action jump mode is as follows:

    • Redirecttoaction ("index");//A parameter is not passed in under this controller.
    • Redirecttoaction (Actionname,controllername)//can jump directly to another controller.
    • Redirecttoroute (New {controller= "home", action= "Index"});//can jump to other controller
    • Redirecttoroute (New {controller= "home", action= "index", Id=param});//can jump to other controller with parameters.
    • Response.Redirect ("index?id=1"), or//for the method name under this controller, can be taken with parameters.
    • Return Redirect ("index");//Applies to the name of the method under this controller.
    • Return view ("index"); Direct display of the corresponding page does not pass the controller's method.
    • Return view ("~/views/home/index.aspx");//This method is to write the full path, directly display the page, without the Controller method
    • return view ()//display the page directly without the Controller method

Jump Direct write full path record in view/home/index?msg=11

Example: Redirecttoaction ("Index", "Home", new {msg= "Operation succeeded", name= "admin"});

Then, if you receive parameters directly in the action method, index (string msg,string name), you can get the arguments passed in, and if you don't want to receive them, use the following method.

    • If you are using the original Index?msg=11&name=simmer then you can use request.querystring["MSG"), then the view is @request.querystring["MSG"]
    • You can use html.viewcontext.routedata.values["MSG" If you are using the routing mechanism of the parameter Index/11/simmer or request.requestcontext.routedata.values["MSG"]

The arguments in MVC and get in view

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.