2013-05-17 13 views
5

Sto provando ad utilizzare Ajax.BeginForm ma senza alcun successo. Non riesco a far funzionare correttamente il mio modulo. Azione del mio controller "UpdateTest" non viene mai chiamato Non so perché. Ho seguito molti tutorial ma ho ancora lo stesso problema. Grazie per l'aiuto !Ajax.BeginForm con ASP.NET MVC 4 che non chiama l'azione del controller

il mio modello:

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

mia azione in ColorController

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

My View

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

risposta

13

Provalo in questo modo ....

@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

Grazie per l'aiuto amico! – user2037696

Problemi correlati