none
求助:razorv3 cshtml jquery 刷新局部 div 的问题 RRS feed

  • 问题

  • 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

    @{
        Page.Title = "qser";
        var msg = "";
        var mid = "";
        Array arylist = null;
        if (IsPost) {
            // **_问题:每次查询的时候,都会把 <manager.cshtml> 一起刷新!这里不知道怎么解决_**
            mid = Request.Form["mid"];
            DBOC dboc = new DBOC();
            arylist = dboc.GetQserById(mid);
        }
    }
    
    <form method="post">
        <input type="text" id="mid" name="mid" value="@mid" />
        <input type="submit" id="submit" name="submit" value="GO" />
    
        <table id="blocks" style="width:600px">
            <thead>
                <tr>
                    <th>会员ID</th>
                </tr>
            </thead>
            <tbody>
                @try
                {
                    if (arylist != null)
                    {
                        foreach (var ary in arylist)
                        {
                            ConstantsClass.QSER qser = (ConstantsClass.QSER)ary;
                    <tr>
                        <td>@qser.Mid</td>
                    </tr>
                        }
                    }
                }
                catch (Exception e)
                {
                    msg = e.ToString();
                }
            </tbody>
        </table>
        @msg
    </form>

    DBOC.cs

    public ArrayList GetQserById(string mid) {
            string sql = string.Format(
                "SELECT * FROM QSER WHERE SERMID = '%{0}%'",
                mid);
            SqlConnection sqlcnn = new SqlConnection(connstr);
            SqlCommand sqlcmm = sqlcnn.CreateCommand();
            sqlcmm.CommandText = sql;
    
            ArrayList arylist = new ArrayList();
            // 用户信息ENTITY
            ConstantsClass.QSER qser = new ConstantsClass.QSER();
    
            sqlcnn.Open();
            SqlDataReader reader = sqlcmm.ExecuteReader();
            if (reader != null)
            {
                while (reader.Read())
                {
                    // 会员ID
                    qser.Cstmid = reader["SERMID"].ToString();
                    arylist.Add(qser);
                }
            }
            return arylist;
    }

    刚接触这个东西,已经卡几天了,还请大家多多帮助,谢谢~



    2016年9月25日 8:16

答案

全部回复