【发布时间】:2014-02-06 19:16:35
【问题描述】:
" 我有一个控制器,它有下拉列表,并且在更改 DDL 时再次绑定调用索引视图并返回将内容加载为的部分视图: 索引控制器:
public ActionResult Index(ProductEntity Prod, string CategoryId)
{
ViewBag.Category = new SelectList(ObjStore.categories, "CategoryId", "CategoryName");
if (Request.IsAjaxRequest())
{
var model = ObjStore.products.Where(x => x.CategoryId == Prod.CategoryId);
return PartialView("_ProductMaster", model);
}
else if (CategoryId != "" && CategoryId !=null)
{
var model = ObjStore.products.Where(x => x.CategoryId == Prod.CategoryId);
return PartialView("_ProductMaster", model);
}
return View();
}
部分视图:
@model IEnumerable<StoreManagement.Models.ProductEntity>
<div id="Products">
@if (Model != null)
{
<table style="width:100%;">
<tr>
<th>Product Name </th>
<th>Max Qty</th>
<th>Min Qty</th>
<th>Edit</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.ProductName.ToString()</td>
<td>@item.MaxQty</td>
<td>@item.MinQty</td>
<td>@Html.ActionLink("Edit","EditProduct",new {ProductId=@item.ProductId},null)</td>
</tr>
}
</table>
}
</div>
在上面我有编辑操作链接,它重定向到编辑视图,在这个页面上,我有返回操作链接,它重定向到索引控制器,查询字符串为 CategoryId,我在选择下拉列表时使用它。
现在我想用 CategoryId 作为查询字符串来加载索引视图。
'其他代码正在为此工作'
if (Request.IsAjaxRequest())
{
var model = ObjStore.products.Where(x => x.CategoryId == Prod.CategoryId);
return PartialView("_ProductMaster", model);
}
else if (CategoryId != "" && CategoryId !=null)
{
var model = ObjStore.products.Where(x => x.CategoryId == Prod.CategoryId);
return PartialView("_ProductMaster", model);
}
但它只返回部分视图。我希望使用他们的 _layout 页面加载该视图。或者如果我们在 URl 中有查询字符串,是否有任何方法可以调用 DDL 的 onchange 事件?或者使 Request.IsAjaxRequest()true。"
【问题讨论】:
-
看看这个,看来这家伙也有类似的问题。 stackoverflow.com/questions/21608567/…
-
没有找到任何解决方案....
标签: c# jquery asp.net-mvc asp.net-mvc-4 razor