5

我正在尝试使用 Ajax.BeginForm 但没有任何成功。我无法让我的表格正常工作。我的控制器操作“UpdateTest”从未被调用我不知道为什么。我遵循了许多教程,但仍然遇到同样的问题。感谢您的帮助 !

我的模型:

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" />
}

Javascript

<script type="text/javascript" src="/Scripts/jquery.unobtrusive-ajax.min.js">
</script>
4

1 回答 1

13

试试这个方法......

@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" />
}
于 2013-05-17T19:38:54.813 回答