In ASP. net mvc, how to enable the ascx user control to have an action/Controller

Source: Internet
Author: User

Generally, in the MVC page, we use the ascx user control to write:

<% = Html. Partial ("adminviewleftmenu") %>

Or write as follows:

<% Html. renderpartial ("~ /Areas/util/views/shared/selectgroup. ascx "); %> 

The difference between the above two reference methods:

Html. renderpartial is directly output to the current httpcontext, while HTML. Partial directly generates a string and returns the View content. Therefore, when referencing, the difference is <% html. renderpartial ("~ /Areas/util/views/shared/selectgroup. ascx "); %> and <% = html. Partial ("~ /Areas/util/views/shared/selectgroup. ascx "); %>.

When you need to add an action to the ascx user control, we need to reference it as follows:

<% Html. renderaction ("Index", "sectiongroup"); %>

The action is as follows:

 Using System;  Using  System. Collections. Generic;  Using  System. LINQ;  Using  System. Web;  Using  System. Web. MVC;  Namespace  Educationmanage. Areas. util. controllers {  Using  Utility. JSON;  Using Educationmanage. Areas. util. models;  Public   Class  Sectiongroupcontroller: controller {  //            //  Get:/util/sectiongroup/ Selectgroupentities = New  Selectgroupentities ();  Public  Actionresult index () {list <Sg_admission_batchs> admissionbatchlist =Selectgroupentities. admission_batchs.tolist (); selectlist admissionbatch = New Selectlist (admissionbatchlist, "  Admission_batch_id  " , "  Name  " , ""  ); Viewdata. Add (  "  Admissionbatch  " , Admissionbatch); List <Sg_education_levels> educationlevellist = Selectgroupentities. education_levels.tolist (); selectlist educationlevel = New Selectlist (educationlevellist, "  Education_id  " , "  Name  " , ""  ); Viewdata. Add (  " Educationlevel  "  , Educationlevel); List <Sg_professional> professionallist = Selectgroupentities. Professional. tolist (); selectlist professional = New Selectlist (explorsionallist, "  Prefessional_code  " , "  Name  " , "" ); Viewdata. Add (  "  Professional  "  , Professional );  ReturnPartialview ("~ /Areas/util/views/shared/sectiongroup. ascx"  );}}}

For more information, seeArticle: Http://leelei.blog.51cto.com/856755/412702/

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.