[英]ASP.Net MVC5: Area Layout changes during RedirectToAction
I've used below snippet to redirect user to different action/views based on selected contract type: 我已使用以下代码段根据所选合同类型将用户重定向到不同的操作/视图:
public ActionResult Create(ContractViewModelCreate contract)
{
if (ModelState.IsValid)
{
if (contract.ContractType == Contract.ContractTypeENUM.SectionBased)
return RedirectToAction("Create", "SectionBasedContract", new { area = "Admin" });
else if (contract.ContractType == Contract.ContractTypeENUM.UnitBased)
return RedirectToAction("Create", "UnitBasedContract", new { area = "Admin" });
else
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Utils.AddErrorsString(ModelState, "Select project type");
return View(contract);
}
However the first RedirectToAction
leads to reading of layout file by running _ViewStart.cs in Admin
area and 2nd one leads to running to _ViewStart.cs in root application area and don't care about Route Objects (to run in Admin Area). 但是,第一个
RedirectToAction
通过在Admin
区域中运行_ViewStart.cs导致读取布局文件,而第二个RedirectToAction
导致在根应用程序区域中运行_ViewStart.cs而不关心路由对象(在Admin区域中运行)。 Since this action is running inside Admin area running of return RedirectToAction("Create", "UnitBasedContract", new { area = "Admin" });
由于此操作在
return RedirectToAction("Create", "UnitBasedContract", new { area = "Admin" });
Admin区域内运行, lead to layout change. 导致布局更改。
I cannot find the reason, does anyone knows the reason? 我找不到原因,有人知道原因吗?
The problem caused by the fact that I forgot to move View files of UnitBasedContractController
to Admin
area and I had left them in global application area. 由于我忘记将
UnitBasedContractController
View文件移动到Admin
区域而将它们留在全局应用程序区域中而导致的问题。 So the _ViewStart.cs
of global Views called for my Views. 因此,全局视图的
_ViewStart.cs
调用了我的视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.