我有一个post方法,在表单中有一个隐藏ID,我想在重定向到get方法时在另一个get方法参数中使用相同的Id,我有可能做到这一点吗?
这个控制器正在努力实现......
public ActionResult AddMenu(int id)
{
var menu = new MenuItemViewModel();
//Get the vendor you want to create menu for
var vendor = _vendorService.GetVendorById(id);
// check if vendor is null
if (vendor != null)
{
menu.VendorId = vendor.Id;
}
else
{
return HttpNotFound();
}
return View(menu);
}
// POST: Vendor/AddMenu/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult AddMenu(MenuItemViewModel menu)
{
if (ModelState.IsValid)
{
_vendorService.AddMenu(menu.VendorId, menu.MenuName);
return RedirectToAction("MenuDetails");
}
else
{
ModelState.AddModelError("", "Menu not created! something went wrong, please try again");
return View();
}
}
public ActionResult GetMenu(int id)
{
MenuItemViewModel item = new MenuItemViewModel();
item.VendorId = id;
return RedirectToAction("MenuDetails");
}
//GET: Vendor/MenuDetails/1
public ActionResult MenuDetails(MenuItemViewModel item)
{
var model = new MenuViewModel();
var foodType = _vendorService.GetAllType().Select(x => new SelectListItem
{
Value = x.Id.ToString(),
Text = x.Name
});
model.Type = foodType.AsEnumerable();
var menu = _vendorService.GetMenuByVendor(item.VendorId);
if (menu != null)
{
model.MenuId = menu.Id;
model.MenuName = menu.MenuName;
model.VendorId = menu.VendorId;
model.VendorName = menu.Vendor.CompanyName;
model.Items = menu.Items.Select(x => x.Name);
}
return View(model);
}
使用上层控制器添加菜单,我想在重定向到MenuDetails页面时获取供应商ID ...
然后使用“获取”菜单直接从操作按钮获取MenuDetails页面。
所以怎么做才能让我按照自己想要的方式工作......
谢谢你的时间。