周末加班,闲来无事,写篇博客,讲讲怎么在 ASP.NET MVC2中使用用户控件。首先我们新建一个用户控件,
我们命名为SelectGroup.ascx,代码如下
双击代码全选
1
|
<ol class = "dp-xml" ><li><p><%@ Control Language= "C#" Inherits= "System.Web.Mvc.ViewUserControl" %> </p></li><li><p><script language= "javascript" type= "text/javascript" src= "<%=Url.Content(" ~/Areas/Util/Scripts/SelectGroup.js ") %>" ></script> </p></li><li><p><div> </p></li><li><p> <table> </p></li><li><p> <tr> </p></li><li><p> <td style= "text-align:right" > </p></li><li><p> 招生批次 </p></li><li><p> </td> </p></li><li><p> <td> </p></li><li><p> <select id= "admissionBatch" style= "width: 150px" > </p></li><li><p> </select> </p></li><li><p> </td> </p></li><li><p> <td style= "text-align:right; width:80px" > </p></li><li><p> 学历层次 </p></li><li><p> </td> </p></li><li><p> <td> </p></li><li><p> <select id= "edcuationLevel" style= "width: 150px" > </p></li><li><p> </select> </p></li><li><p> </td> </p></li><li><p> <td style= "text-align:right; width:80px" > </p></li><li><p> 专业名称 </p></li><li><p> </td> </p></li><li><p> <td> </p></li><li><p> <select id= "professional" style= "width: 150px" > </p></li><li><p> </select> </p></li><li><p> </td> </p></li><li><p> </tr> </p></li><li><p> </table> </p></li><li><p></div> </p></li></ol>
|
我们再编写其对应的控制器如下
双击代码全选
1
2
3
4
5
6
7
8
9
10
11
12
13
|
<ol class = "dp-c" ><li><p> using System; </p></li><li><p> using System.Collections.Generic; </p></li><li><p> using System.Linq; </p></li><li><p> using System.Web; </p></li><li><p> using System.Web.Mvc; </p></li><li><p> </p></li><li><p> namespace EducationManage.Areas.Util.Controllers </p></li><li><p>{ </p></li><li><p> using Utility.Json; </p></li><li><p> using EducationManage.Areas.Util.Models; </p></li><li><p> public class SelectGroupController : Controller </p></li><li><p> { </p></li><li><p> // </p></li><li><p> // GET: /Util/SelectGroup/ </p></li><li><p> SelectgroupEntities selectgroupEntities = new SelectgroupEntities(); </p></li><li><p> </p></li><li><p> /// <summary> </p></li><li><p> /// 招生批次 </p></li><li><p> /// 李磊 2010-10-29 </p></li><li><p> /// </summary> </p></li><li><p> /// <returns></returns> </p></li><li><p> public JsonResult GetAdmissionBatch() </p></li><li><p> { </p></li><li><p> List<SG_Admission_Batchs> admissionBatchsList = selectgroupEntities.admission_batchs.ToList(); </p></li><li><p> return Json(admissionBatchsList, JsonRequestBehavior.AllowGet); </p></li><li><p> } </p></li><li><p> </p></li><li><p> /// <summary> </p></li><li><p> /// 学历层次 </p></li><li><p> /// 李磊 2010-10-29 </p></li><li><p> /// </summary> </p></li><li><p> /// <returns></returns> </p>
<div style= " display:block; width:100%; padding-top:15px; margin:0px auto; height:90px; overflow:hidden; text-align:center;" ><script src= "/2011/ads/tech_content_end_468x60.js" ></script><script type= "text/javascript" ><!--
google_ad_client = "pub-5977682010997732" ;
/* 468x60, 09-9-9 */
google_ad_slot = "4048873275" ;
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type= "text/javascript" src= "http://pagead2.googlesyndication.com/pagead/show_ads.js" >
</script><ins style= "display:inline-table;border:none;height:60px;margin:0;padding:0;position:relative;visibility:visible;width:468px" ><ins id= "aswift_1_anchor" style= "display:block;border:none;height:60px;margin:0;padding:0;position:relative;visibility:visible;width:468px" ><iframe allowtransparency= "true" hspace= "0" marginwidth= "0" marginheight= "0" onload= "var i=this.id,s=window.google_iframe_oncopy,H=s&&s.handlers,h=H&&H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&&d&&(!d.body||!d.body.firstChild)){if(h.call){i+='.call';setTimeout(h,0)}else if(h.match){i+='.nav';w.location.replace(h)}s.log&&s.log.push(i)}" vspace= "0" id= "aswift_1" name= "aswift_1" style= "left:0;position:absolute;top:0;" frameborder= "0" height= "60" width= "468" scrolling= "no" ></iframe></ins></ins>
</div>
</li></ol>
|
发表回复