我有2个局部视图(一个gridview和回调面板)ASP.NET MVC设计问题
此主视图接收IEnumerable<Model>
和面板刚刚接收Model
的主视图。
当最初调用视图时,面板的局部视图将填充空模型,因此它是空的。
但是我想在我的GridView中点击Edit
来重新渲染面板。
我该如何做到这一点?
我目前在编辑按钮中有一个@Html.ActionLink
,但它不起作用,因为它会创建一个新的视图,而不是渲染面板的局部视图。
任何线索?
编辑:
这是我的编辑:
Html.ActionLink("Edit", "EditConfig", new { id = DataBinder.Eval(c.DataItem, "QueueMonitorConfigurationsID") })
该功能可在编辑链接调用:
[HttpGet]
public ActionResult EditConfig(int id)
{
StorageConfigurationModel resultForPanel = new StorageConfigurationModel { };
IEnumerable<StorageConfigurationModel> configList = (IEnumerable<StorageConfigurationModel>)Session["ConfigurationList"];
foreach (StorageConfigurationModel configModel in configList)
{
if (configModel.QueueMonitorConfigurationsID == id)
{
resultForPanel = configModel;
break;
}
}
return PartialView("cbpnlNewUpdateConfigs", resultForPanel);
}
主视图中包含的部分观点:
@model IEnumerable<BPM.Website.Models.StorageConfigurationModel>
@Html.Partial("gvConfigurations", Model)
@Html.Partial("cbpnlNewUpdateConfigs", new BPM.Website.Models.StorageConfigurationModel { QueueMonitorConfigurationsID = -1 })
那么我该如何传递参数呢?在我的情况下,我传递一个'id',所以我知道我必须显示的Model ID – AAlferez
您只需将要编辑的记录的id作为routeValues参数的一部分传递给Ajax.ActionLink助手,如我的答案中所示。由于每条记录都有一个编辑链接,因此您已经知道记录的编号。然后,Ajax.ActionLink将生成一个具有以下格式的url:'/ somecontroller/edit/123',其中'123'当然是要编辑的记录的ID。而你的编辑控制器动作只需要这个'id'参数作为参数。 –
这是完全一样的。也许我所称的功能是问题。 – AAlferez