Submit Data from partial view to a controller MVC

扶醉桌前 提交于 2019-11-30 16:48:20

Answer 1: First try this and let me know if that hits your controller.

 @using (Html.BeginForm("AddEmployment", "Application", FormMethod.Post))

Answer 2: To update the employment list, I would assume you would want to save the model to your database then have your employment list displayed on the same page or a different page calling the data from the DB into the the list or table to be displayed.

Edit: It looks as though your form attributes are not being applied. For your employment.cshtml, I personally don't use { } around my @Html statements. You must not be doing what I stated above because your error occurs only when I write it as

 @using (Html.BeginForm("AddEmployment, Application", FormMethod.Post))

missing those closing quotes is what is causing your problem.

Rakesh Jogani

jQuery code:

window.jQuery(document).ready(function () {
    $('#btnsave').click(function () {

        var frm = $("form");
        var data = new FormData($("form")[0]);
        debugger;
        $.ajax({
            url: '/Home/Update',
            type: "POST",
            processData: false,
            data: data,
            dataType: 'json',
            contentType: false,
            success: function (response) {
                alert(response);
            },
            error: function (er) { }
        });
        return false;
    });

});

Controller Code

[HttpPost]
    public JsonResult Update(Generation obj)
    {
        if (ModelState.IsValid)
        {
            return Json("done");
        }
        else
        {
            return Json("error create");
        }
    }

Using those code you can post form using jquery and get response in jsonresult

you have put @using (Html.BeginForm("AddEmployment, Application")) what this is trying to do is invoke a action called "AddEmployment, Application" i think you meant @using (Html.BeginForm("AddEmployment", "Application"))

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!