C# ASP.NET MVC 4中的Ajax.BeginForm不调用控制器操作
我正在尝试使用Ajax.BeginForm,但没有成功。我无法使我的表格正常工作。我的控制器操作“UpdateTest”从未被调用,我不知道为什么。我学习了很多教程,但仍然遇到同样的问题。谢谢你的帮助 我的模型:C# ASP.NET MVC 4中的Ajax.BeginForm不调用控制器操作,c#,asp.net,.net,asp.net-mvc,ajax.beginform,C#,Asp.net,.net,Asp.net Mvc,Ajax.beginform,我正在尝试使用Ajax.BeginForm,但没有成功。我无法使我的表格正常工作。我的控制器操作“UpdateTest”从未被调用,我不知道为什么。我学习了很多教程,但仍然遇到同样的问题。谢谢你的帮助 我的模型: public class TestModel { public ObjectId _id { get; set; } public int orange { get; set; } public int blue { get; set; } public
public class TestModel
{
public ObjectId _id { get; set; }
public int orange { get; set; }
public int blue { get; set; }
public int red { get; set; }
public int yellow { get; set; }
public int white { get; set; }
public float green { get; set; }
public float pink { get; set; }
}
我在ColorController中的操作
[HttpPost]
public void UpdateTest(TestModel tmp)
{
...
...
}
我的看法
@model Project.Models.TestModel
@using (Ajax.BeginForm(new AjaxOptions()
{
HttpMethod = "POST",
Url = Url.Action("UpdateTest", "Color")
}))
{
@Html.TextBoxFor(model => model._id)
@Html.TextBoxFor(model => model.orange)
@Html.TextBoxFor(model => model.blue)
@Html.TextBoxFor(model => model.red)
@Html.TextBoxFor(model => model.yellow)
@Html.TextBoxFor(model => model.white)
@Html.TextBoxFor(model => model.green)
@Html.TextBoxFor(model => model.pink)
<input type="submit" value="Submit" />
}
@model Project.Models.TestModel
@使用(Ajax.BeginForm)(新的AjaxOptions()
{
HttpMethod=“POST”,
Url=Url.Action(“UpdateTest”、“Color”)
}))
{
@Html.TextBoxFor(model=>model.\u id)
@Html.TextBoxFor(model=>model.orange)
@Html.TextBoxFor(model=>model.blue)
@Html.TextBoxFor(model=>model.red)
@Html.TextBoxFor(model=>model.yellow)
@Html.TextBoxFor(model=>model.white)
@Html.TextBoxFor(model=>model.green)
@Html.TextBoxFor(model=>model.pink)
}
Javascript
<script type="text/javascript" src="/Scripts/jquery.unobtrusive-ajax.min.js">
</script>
这样试试
@using (Ajax.BeginForm("UpdateTest", "Color", new AjaxOptions() { HttpMethod = "POST" }))
{
@Html.TextBoxFor(model => model._id)
@Html.TextBoxFor(model => model.orange)
@Html.TextBoxFor(model => model.blue)
@Html.TextBoxFor(model => model.red)
@Html.TextBoxFor(model => model.yellow)
@Html.TextBoxFor(model => model.white)
@Html.TextBoxFor(model => model.green)
@Html.TextBoxFor(model => model.pink)
<input type="submit" value="Submit" />
}
@使用(Ajax.BeginForm(“UpdateTest”,“Color”,new-AjaxOptions(){HttpMethod=“POST”}))
{
@Html.TextBoxFor(model=>model.\u id)
@Html.TextBoxFor(model=>model.orange)
@Html.TextBoxFor(model=>model.blue)
@Html.TextBoxFor(model=>model.red)
@Html.TextBoxFor(model=>model.yellow)
@Html.TextBoxFor(model=>model.white)
@Html.TextBoxFor(model=>model.green)
@Html.TextBoxFor(model=>model.pink)
}
谢谢你的帮助,伙计!