manager.cshtml
@{ <script type="text/javascript" src="~/Scripts/jquery.js"></script> Layout = "~/_SiteLayout.cshtml"; Page.Title = "main"; <script type="text/javascript"> $(document).ready(function () { $("#btnQser").click(function () { alert('data'); // **_动态加载 qser.cshtml_** $("#result").load("qser.cshtml"); }); }); </script> } <hgroup class="title"> <h1>@Page.Title</h1> </hgroup> <table> <tr> <td> <input type="button" id="btnQser" value="qser" /> </td> </tr> <tr> <td> <div id="result"> <!-- 每次只刷新这里就好 --> </div> </td> </tr> </table>
qser.cshtml
1 @{ 2 Page.Title = "qser"; 3 var msg = ""; 4 var mid = ""; 5 Array arylist = null; 6 if (IsPost) { 7 // **_问题:每次查询的时候,都会把 <manager.cshtml> 一起刷新!这里不知道怎么解决_** 8 mid = Request.Form["mid"]; 9 DBOC dboc = new DBOC(); 10 arylist = dboc.GetQserById(mid); 11 } 12 } 13 14 <form method="post"> 15 <input type="text" id="mid" name="mid" value="@mid" /> 16 <input type="submit" id="submit" name="submit" value="GO" /> 17 18 <table id="blocks" style="width:600px"> 19 <thead> 20 <tr> 21 <th>会员ID</th> 22 </tr> 23 </thead> 24 <tbody> 25 @try 26 { 27 if (arylist != null) 28 { 29 foreach (var ary in arylist) 30 { 31 ConstantsClass.QSER qser = (ConstantsClass.QSER)ary; 32 <tr> 33 <td>@qser.Mid</td> 34 </tr> 35 } 36 } 37 } 38 catch (Exception e) 39 { 40 msg = e.ToString(); 41 } 42 </tbody> 43 </table> 44 @msg 45 </form>
DBOC.cs
1 public ArrayList GetQserById(string mid) { 2 string sql = string.Format( 3 "SELECT * FROM QSER WHERE SERMID = '%{0}%'", 4 mid); 5 SqlConnection sqlcnn = new SqlConnection(connstr); 6 SqlCommand sqlcmm = sqlcnn.CreateCommand(); 7 sqlcmm.CommandText = sql; 8 9 ArrayList arylist = new ArrayList(); 10 // 用户信息ENTITY 11 ConstantsClass.QSER qser = new ConstantsClass.QSER(); 12 13 sqlcnn.Open(); 14 SqlDataReader reader = sqlcmm.ExecuteReader(); 15 if (reader != null) 16 { 17 while (reader.Read()) 18 { 19 // 会员ID 20 qser.Cstmid = reader["SERMID"].ToString(); 21 arylist.Add(qser); 22 } 23 } 24 return arylist; 25 }
刚刚才注册到博客园,还望各位大侠不吝赐教!谢谢了
提示一下:$("#result").load("qser.cshtml");
这是 GET
方式请求的。
哪儿有load"cshtml"这种文件的???(不是说完全不能,但没人这么玩儿过)
谢谢
先用iframe 解决问题了