我的模型有一个包含多个输入的视图(Html.TextBoxFor(x => x.attribute) 等)。我的ajax 方法是:
function callMethod() {
$.ajax({
type: "POST",
data: $('#Form').serialize() ,
url: '@Url.Action("formMethod", "Test")',
}).done(function (newTable) {
$('#RefundTableDiv').html(newTable);
});
};
Run Code Online (Sandbox Code Playgroud)
这工作得很好,模型完美地适合 formMethod,但是当我更改 formMethod 并添加另一个参数(例如“int test”)时,它不再工作。
我的方法如下所示:
function callMethod() {
var number = 2;
$.ajax({
type: "POST",
data: {"model": $('#Form').serialize(),
"test": number},
url: '@Url.Action("formMethod", "Test")',
}).done(function (newTable) {
$('#RefundTableDiv').html(newTable);
});
};
Run Code Online (Sandbox Code Playgroud)
“测试”:数字确实正确地到达控制器中的方法,但模型现在突然为空?
我究竟做错了什么?
我有一个ViewBag,它是我在控制器中创建的列表:
List<string> listoflists = new List<string>();
Run Code Online (Sandbox Code Playgroud)
然后它会填充一些字符串,例如:
listoflists.Add("java");
listoflists.Add("php");
listoflists.Add("C#");
Run Code Online (Sandbox Code Playgroud)
将其添加到ViewBag:ViewBag.listoflists = listoflists;
我想在我的View中检查它是否包含特定的字符串:
@if(ViewBag.listoflists.contains("java")
{
// do html stuff
}
Run Code Online (Sandbox Code Playgroud)
但是在运行时我收到以下错误:
System.Collections.Generic.List不包含contains的定义
我做错了什么,或者如何查看列表中是否包含某些内容?