【发布时间】:2016-10-07 06:15:35
【问题描述】:
我的要求是将 string 值从 javascript 传递给控制器。
ActionResult 方法调用正确,但字符串的参数类型总是为空。
JavaScript:
var contents = 'M1234';
$.get('/Sched/GetInformation/' + contents, {},
function (data, status) {
if (!data.success) {
alert('test');
}
});
控制器:
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "")]
public ActionResult GetInformation(string mID)
{
bool superficialCheck = true;
return Json(new { success = superficialCheck },
JsonRequestBehavior.AllowGet);
}
注意: 控制器名称为 SchedController
mID 总是得到null 值
【问题讨论】:
-
你试过把mID改成id吗?
-
您是否有使用
...{mID}定义的特定路由? (否则它需要是string id)。无论如何,您应该使用$.get('@Url.Action("GetInformation", "Sched")', { mID: contents }, function() {... -
您好,您可以试试 "?mId="+contents 或 "/mId/"+contents ...请在 Global.asax 中发布您的路线设置吗?
-
@sachin,
id是否区分大小写? -
@User1674987,编号
标签: javascript c# jquery asp.net-mvc