部分页面未加载到同一页面上

时间:2014-05-20 10:15:11

标签: asp.net-mvc-3 razor

这是我的代码已在.chtml页面中实现。当我点击按钮对应页面打开新页面而不是同一页面。我想在同一个视图页面上打开该部分页面。请帮帮我..提前致谢..

  <div class="contentbox">
        <div class="contentmain">
          @using (Ajax.BeginForm("SearchForEdit", "Home", FormMethod.Post, new AjaxOptions { UpdateTargetId = "update_panel", InsertionMode = InsertionMode.Replace }, new { @class = "form-horizontal" }))
          {                
             <ul>
                <li><div class="leftc_box" style="width:150px;">Enter Id or Song Name </div>
                <div class="rightc_box">
                <input type="text" name="entryid" value="" placeholder="Enter Id or Song Name" style="height: 30px;"  />
                </div>
                </li>
                <li>
                <div class="leftc_box" style="margin-left:153px;"><input type="image" name="" src="../../Content/img/submit.png" value="" /></div>
                </li>
            </ul>              
                <div id="update_panel">@Html.Partial("SearchForEdit")</div>                                                         
          }
            <div>
                <table style="border-style: solid; border-width: thin; height: auto; width: 100%; margin-top: 8px;">
                    <tr style="background: #f4f4f4;">
                        <th align="center">ID</th>
                        <th align="center">Song Name</th>
                        <th align="center">Album Name</th>
                        <th align="center">Label Name</th>
                    </tr>
                    @foreach (xxxxxxxxxxx ienctry in obmain)
                    {
                        <tr class="divset">
                            <td align="center">@ienctry.id</td>
                            <td align="center">@ienctry.Song</td>
                            <td align="center">@ienctry.Album</td>
                            <td align="center">@ienctry.Label</td>
                        </tr>
                    }
                </table>
            </div>               
        </div>
    </div>

我的控制器就是这个......

[HttpPost]
        public ActionResult SearchForEdit(int entryid)
        {
            ViewBag.searchid = entryid;
            return PartialView("SearchForEdit");
        }

这是我的部分页面......

@{    
    int ssid = 0;
     if(ViewBag.searchid!=null)
     {
         ssid = ViewBag.searchid;
     }
                      List<XXXXXXXX> mainobject = XXXXXXXXXXXXXXXXX.Service.Class1.SearchnUpdate(ssid);
                      ViewBag.Title = "title";

}

<div>
 <table style="border-style: solid; border-width: thin; height: auto; width: 100%; margin-top: 8px;">

@if (mainobject.Count > 0)
{
     <tr style="background: #f4f4f4;">
                            <th align="center">ID</th>
                            <th align="center">Song Name</th>
                            <th align="center">Album Name</th>
                            <th align="center">Label Name</th>
                            <th align="center"></th>
                        </tr>
    foreach (XXXXXXXXXX ientry in mainobject)
    {
   <tr style="background: #f4f4f4;">
    <td align="center">@ientry.id</td>
    <td align="center">@ientry.Song</td>
    <td align="center">@ientry.Album</td>
    <td align="center">@ientry.Label</td>
    <td align="right"><a href=""><img src="../../Content/img/update.png"</a></td>
    </tr>
}
}
</table>
</div>

这是我的方法已在class1页面中定义..

public static List<xxxx> SearchnUpdate(int searchid)
        {
            string ssongname=searchid.ToString();
            List<xxxx> obj = new List<xxxx>();
            using (xxxxxxxxx dbcontext = new xxxxxxxxxx())
            {
                obj = (from z in dbcontext.xxxxx where z.id == searchid || z.Song == ssongname select z).ToList();
            }
            return obj;
        }

0 个答案:

没有答案