ASP. net mvc loads a user control and obtains its value or value assignment.

Source: Internet
Author: User

Some netizens read this article ASP. net mvc after loading ASCX, and for the value of the http://www.cnblogs.com/insus/p/3643254.html, asked Insus. NET. Instead of assigning values in the control controller, you want to use jQuery in the view to obtain or assign values to the control values in the user control. What should we do?

The following Insus. NET takes less time to give a simple example to demonstrate and share the implementation methods.

 
Before implementation, modify the public static HtmlString RenderControl <T> (string path) method in the AscxUtility. cs class.

 

Because Web Control must be placed in the form to run.


Create a user control Uc1.ascx:

 

In the controller, create two actions:

 

Create View:

 

Mark 3 above is the HTML string obtained from the user control Render and displayed on the Div tag.

Mark 4 and Mark 5 are used to obtain values and assign values.

Real-time Demonstration:

 

The following is another method, which is presented using the Razor syntax. You can follow the four steps below to modify it and avoid writing public ContentResult ShowUc () Action in the controller.

 

The running result remains the same.

 

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.