我是MVC的新手,并试图通过js导航到控制器动作方法。代码工作(如action方法被击中),但参数值,我传递的总是空Asp.net MVC控制器参数null当从javascript调用动作时
JS:
window.location.href = "@Url.Action("Step1", "Reports")" + "/?" + rsid;
控制器动作:
public class ReportsController : Controller {
public ActionResult Step1(int? rsid)
{
//do stuff
}
}
的RSID参数始终为空。我尝试了各种链接格式,例如“/?rsid = [id]”,“/ [id]”
我是否需要一个自定义路由来获取参数?
或者可能用[httpPost]或[httpGet]注释操作方法?
你试过了吗?“@ Url.Action(”Step1“,”Reports“)”+“/?rsid =”+ rsid'? – Neverever
您没有为参数'rsid'提供任何值(所以它'null') –
此外,[下载fiddler](http://www.telerik.com/fiddler)。它很有帮助,看看发送了哪些参数,并且更容易识别问题 – TheUknown