Вопрос

I sent an object to controllers action thorugh ajax , but I don't know how to recevie the object in controller. My ajax call is :

       $.ajax({
            type: "POST",
            url: '@Url.Action("Create","Home")',
            data: { ID: '@Model.ID', Name: '@Model.Name'}
        }).done(function (msg) {
            alert("Added :" + msg);
        });

This should work , BUt I can't figure out how to recevie the object in controller. I wrote this :

    public ActionResult Create(Home h)
    {

    }

But it is not working . I neeed help in this , Thanks in advance.

My Home class :

public class Home
{
    public int ID { get; set; }
    public string Name { get; set; }
}
Это было полезно?

Решение

Your action should be like thus:

[HttpPost]
public ActionResult Create(Home h)
{
    throw new NotImplementedException(); // put you code here
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top