2013-05-17 14 views
5

Próbuję użyć Ajax.BeginForm, ale bez powodzenia. Nie mogę uzyskać prawidłowego działania mojego formularza. My Controller Action "UpdateTest" nigdy nie jest nazywany Nie wiem dlaczego. Podążyłem za wieloma samouczkami, ale wciąż mam ten sam problem. Dziękuję za pomoc!Ajax.BeginForm z ASP.NET MVC 4 nie wywoływanie działania kontrolera

My Model:

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; } 
} 

mojego działania w ColorController

[HttpPost] 
    public void UpdateTest(TestModel tmp) 
    { 
     ... 
     ... 
    } 

moim zdaniem

@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> 

Odpowiedz

13

Wypróbuj w ten sposób ...

@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" /> 
} 
+0

Dzięki za pomoc dla partnera! – user2037696

Powiązane problemy