我有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