我有一个局部页面,它使用两个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请检查更新的代码 –