感谢您阅读本文。
想要将数据从查询字符串传递到操作;URL
MyController/MyAction?lob=a
试过这个:
[HttpGet]
public ActionResult MyAction()
{
var model = new SModel();
model.lob = Request.QueryString["lob"];
return View(model);
}
[HttpGet]
public ActionResult MyAction(string lob)
{
var model = new SModel();
model.lob = lob;
return View(model);
}
[HttpGet]
public ActionResult MyAction(FormCollection values)
{
var model = new SModel();
model.lob = values["lob"];
return View(model);
}
"lob"始终为空。
有什么想法吗?
控制器中应该只有一个 MyAction 方法。
您也可以删除[HttpGet]
public ActionResult MyAction(string lob)
{
var model = new SModel();
model.lob = lob;
return View(model);
}
如果要发布第二个 MyAction,请向其添加[HttpPost]
,以便控制器可以确定使用哪种方法。