有人可以帮我解决一下情况吗?
我有一个项目,我想在每次请求时从我的 url 路径中删除每个控制器和方法。 现在的例子我的每次网址如下所示
www.mywebsite.com/Account/View
但我想从网址中删除/Account/View
您可以尝试TempData
无论您在何处尝试获取希望作为参数传递的属性...例如将它们发布到 ViewModel 中的路由并将它们传递到下一个路由
[HttpPost]
public IAction PageOne(PageViewModel model)
{
// Store the property
TempData["MyProp"] = model.CollectedProperty;
return RedirectToAction("PageTwo");
}
[HttpGet]
public IAction PageTwo(){
PageTwoViewModel model = new PageTwoViewModel();
// Grab the property
model.PropertyWasPassed = (string)TempData["MyProp"];
}
*请注意,TempData 仅持续 1 次请求,然后数据不再可用。