我有一個局部頁面,它使用兩個View頁面不同的控制器,但是有相同的Edit
Action方法。我需要在運行時爲特定頁面動態設置控制器名稱。我該怎麼做 ?如何在局部頁面設置動態控制器名稱
我的部分頁面_SearchProduct
在它的工作只爲WomanController
操作方法Edit
共享文件夾:
<div class="row">
<div class="col-md-6">
@using (Html.BeginForm("Edit", "Woman", FormMethod.Get))
{
<p>
Find by Product Id : @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
<input type="submit" value="Search" />
</p>
}
</div>
<div class="col-md-6">
<span style="color:green">@ViewBag.ProductName </span>
</div>
<span style="color:red"> @ViewBag.FindResult </span>
</div>
我WomanController
編輯頁:
@model MKL.Models.WomanProduct
<hr />
@Html.Partial("~/Views/Shared/_SearchProduct.cshtml")
<hr />
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.WomanProductId)
@if (ViewBag.ProductId != null)
{
@Html.Hidden("ProductId", (int)ViewBag.ProductId)
}
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
我ManController
編輯頁:
@model MKL.Models.ManProduct
<hr />
@Html.Partial("~/Views/Shared/_SearchProduct.cshtml")
<hr />
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.ManProductProductId)
@if (ViewBag.ProductId != null)
{
@Html.Hidden("ProductId", (int)ViewBag.ProductId)
}
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}
SO需要動態地設定局部視圖控制器名稱Man
和Woman
@using (Html.BeginForm("Edit", "", FormMethod.Get)){}
使用'Html.Action'渲染局部視圖並通過ViewBag傳遞控制器名稱並將其設置在'view'中。需要更多的信息,當你打電話給這個部分頁面,然後我們可以讓你知道確切的解決方案。 –
@GuruprasadRao請檢查更新的代碼 –