ASP.NET MVC Ajax Post没有数据

时间:2018-06-12 02:51:57

标签: ajax asp.net-mvc razor asp.net-ajax

我在这个问题上挣扎太久了,也许我错过了一些简单的事情。我一直在尝试使用ajax表单,以避免在提交表单后重新加载整个页面。一切都很好看,Chrome DevTools显示了一个包含我所有数据的好帖子。当我在控制器中执行操作时,我的视图模型为空并处于初始化状态。所以我的意思是它与值在服务器端映射到我的模型的方式有关。

这是我的代码,我的目标不仅仅是这个,但是在尝试排除故障时我已经剥离了很多。我觉得这是Ajax表单帖子最基本的形式。我尝试将名称和变量设为通用的,以便尝试和简化,所以如果有些事情不能加起来可能就是原因。

请帮助我疯了。

查看:

@model EmiExpress.Web.Areas.Reports.Models.TurnkeyLiability.AddNewReportFormVm
@using (Ajax.BeginForm("NewReport", "Reports",
    new AjaxOptions { HttpMethod = "POST" } ))
{

    <div>
        @Html.TextBoxFor(model => model.GroupId)
    </div>
    <div>
        @Html.DevExpress().CheckBoxFor(
            model => model.Save, 
            s =>
            {
                s.Text = "Save Values?";
            }
            ).GetHtml()
    </div>
    <div>
        <input type="submit" value="Submit Data" id="btnSubmit" />
    </div>
}

控制器操作:

[HttpPost]
        public ActionResult NewReport(AddNewReportFormVm viewModel)
        {
            int x = 5;
            if (ModelState.IsValid)
            {
                x = 10; //just some junk while I try to get this working
            }

            return PartialView("Controls/_cbpReportRunLoading", x);
        }

型号:

public class AddNewReportFormVm
    {
        public AddNewReportFormVm()
        {
            GroupId = "";
            Save = false;
        }


        [Required]
        public string GroupId{ get; private set; }

        public bool Save{get; set;}
    }

网络响应标头:

Cache-Control: private
Content-Length: 1130
Content-Type: text/html; charset=utf-8
Date: Tue, 12 Jun 2018 02:41:05 GMT
Persistent-Auth: true
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-AspNetMvc-Version: 5.2
X-Powered-By: ASP.NET
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcc3RlZmFudG91YmlhXHNvdXJjZVxyZXBvc1xFbWlFeHByZXNzXEVtaUV4cHJlc3MuV2ViXFJlcG9ydHNcVHVybmtleUxpYWJpbGl0eVxSdW5OZXdSZXBvcnQ=?=

请求标题:

Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Connection: keep-alive
Content-Length: 2300
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
DXCss: 0_2312,1_50,1_53,1_51,0_2317,1_40,1_17,0_2214,1_16,0_2219,0_2221,0_2225,1_18,1_4,0_2257,18_3,18_11,18_7,0_2261,0_2313,1_34,0_2273,16_3,16_11,16_7,0_2277,1_44,0_2192,24_359,24_364,24_360,1_20,9_12,9_15,0_2338,9_1,0_2342,9_4,1_7,15_0,15_4,/Content/Site.css,/Areas/Reports/Content/TurnkeyLiability.css
DXScript: 1_228,1_226,1_227,1_225,1_304,1_211,1_185,1_221,1_188,1_182,1_280,1_293,1_271,1_287,1_290,1_184,17_42,17_3,1_286,1_189,17_8,1_298,1_193,17_10,1_288,1_195,1_194,17_11,1_209,1_217,1_296,1_279,1_302,1_254,1_235,1_247,1_303,1_222,17_12,1_297,17_41,1_190,1_223,1_291,1_289,1_196,1_256,1_263,1_262,1_255,1_252,1_259,1_253,1_261,1_258,1_257,1_248,1_244,1_242,1_251,1_250,1_249,1_246,1_245,1_260,1_241,1_238,1_239,1_240,1_243,17_15,17_17,1_272,1_273,17_19,1_274,1_275,17_20,17_21,1_224,17_14,1_277,17_24,17_28,1_281,17_25,1_294,17_27,1_292,1_295,17_32,1_299,17_36,17_40,1_192,1_285,18_36,18_38,18_33,18_42,18_37,18_35,17_31,1_208,1_206,1_212,1_201,1_215,1_203,1_205,1_204,1_284,1_198,1_213,17_1,1_197,17_0,1_199,17_2,1_200,17_4,1_202,1_219,17_7,17_23,1_207,17_9,1_276,1_216,17_22,1_214,1_218,17_38,1_220,16_52,16_152,16_47,16_36,16_153,16_28,16_27,16_48,16_50,16_32,16_41,16_159,16_154,16_34,16_51,16_54,16_40,16_158,16_43,16_44,16_33,16_162,16_46,16_45,16_55,16_49,16_31,16_38,16_37,16_39,16_53,16_42,16_26,16_29,16_30,17_35,16_160,16_35,10_11,10_10,10_12,10_13,10_14,17_6,1_236,17_16,1_229,24_401,24_400,24_402,24_403,24_406,24_407,24_408,24_404,24_405,1_230,24_379,24_380,9_45,9_36,24_388,24_398,9_38,9_37,17_30,9_46,17_44,9_42,9_39,9_31,17_29,9_41,9_32,9_44,9_43,9_40,15_16,15_14,15_10,15_11,15_13,20_0,1_237,9_48,9_47
Host: localhost:57144
Origin: http://localhost:57144
Referer: http://localhost:57144/Reports/TurnkeyLiability
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36
X-Requested-With: XMLHttpRequest

表格数据:

GroupId: abc
Save: C
DXScript: 1_228,1_226,1_227,1_225,1_304,1_211,1_185,1_221,1_188,1_182,1_280,1_293,1_271,1_287,1_290,1_184,17_42,17_3,1_286,1_189,17_8,1_298,1_193,17_10,1_288,1_195,1_194,17_11,1_209,1_217,1_296,1_279,1_302,1_254,1_235,1_247,1_303,1_222,17_12,1_297,17_41,1_190,1_223,1_291,1_289,1_196,1_256,1_263,1_262,1_255,1_252,1_259,1_253,1_261,1_258,1_257,1_248,1_244,1_242,1_251,1_250,1_249,1_246,1_245,1_260,1_241,1_238,1_239,1_240,1_243,17_15,17_17,1_272,1_273,17_19,1_274,1_275,17_20,17_21,1_224,17_14,1_277,17_24,17_28,1_281,17_25,1_294,17_27,1_292,1_295,17_32,1_299,17_36,17_40,1_192,1_285,18_36,18_38,18_33,18_42,18_37,18_35,17_31,1_208,1_206,1_212,1_201,1_215,1_203,1_205,1_204,1_284,1_198,1_213,17_1,1_197,17_0,1_199,17_2,1_200,17_4,1_202,1_219,17_7,17_23,1_207,17_9,1_276,1_216,17_22,1_214,1_218,17_38,1_220,16_52,16_152,16_47,16_36,16_153,16_28,16_27,16_48,16_50,16_32,16_41,16_159,16_154,16_34,16_51,16_54,16_40,16_158,16_43,16_44,16_33,16_162,16_46,16_45,16_55,16_49,16_31,16_38,16_37,16_39,16_53,16_42,16_26,16_29,16_30,17_35,16_160,16_35,10_11,10_10,10_12,10_13,10_14,17_6,1_236,17_16,1_229,24_401,24_400,24_402,24_403,24_406,24_407,24_408,24_404,24_405,1_230,24_379,24_380,9_45,9_36,24_388,24_398,9_38,9_37,17_30,9_46,17_44,9_42,9_39,9_31,17_29,9_41,9_32,9_44,9_43,9_40,15_16,15_14,15_10,15_11,15_13,20_0,1_237,9_48,9_47
DXCss: 0_2312,1_50,1_53,1_51,0_2317,1_40,1_17,0_2214,1_16,0_2219,0_2221,0_2225,1_18,1_4,0_2257,18_3,18_11,18_7,0_2261,0_2313,1_34,0_2273,16_3,16_11,16_7,0_2277,1_44,0_2192,24_359,24_364,24_360,1_20,9_12,9_15,0_2338,9_1,0_2342,9_4,1_7,15_0,15_4,/Content/Site.css,/Areas/Reports/Content/TurnkeyLiability.css
DXMVCEditorsValues: {"Save":true}
X-Requested-With: XMLHttpRequest

0 个答案:

没有答案