ASP.NET MVC action does not recognise post json data -


I have this form 3 field, which I want to do in controller action:

  & Lt; Form role = "form" class = "form-inline" name = "frmUserData" id = "frmUserData" & gt; & Lt; Div class = "form-group" & gt; & Lt; Label = "txtlitm" & gt; Item code: & lt; / Label & gt; & Lt; Input type = "text" class = "form-control" id = "txtlitm" name = "txtlitm" & gt; & Lt; / Div & gt; & Lt; Div class = "form-group" & gt; & Lt; Label = "txtmcu" & gt; Branch Plant (filter): & lt; / Label & gt; & Lt; Input type = "text" class = "form-control" id = "txtmcu" name = "txtmcu" & gt; & Lt; / Div & gt; & Lt; Div class = "form-group" & gt; & Lt; Label = "txtlocn" for & gt; Location (filter): & lt; / Label & gt; & Lt; Input type = "text" class = "form-control" id = "txtlocn" name = 'txtlocn' & gt; & Lt; / Div & gt; & Lt; Button type = "button" class = "btn btn-default" id = "btnggo" & gt; Search & lt; / Button & gt; & Lt; / Form & gt;   

My Javascript: version 1:

  $ ajax ({type: "post", data: JSON.stringify (. $ ( '# frmUserData') serializeArray ()), contentType: "application / json; charset = utf-8", url: action, datatype: 'HTML', success: function (data) {$ (dataContainer). Html (data); $ (what) .hide ();}   

version 2:

  $ .ajax ( {type: "POST", data: '{ "frmData":' + JSON.stringify + '}', contentType ($ ( '# frmUserData') serializeArray ().): "application / json; charset = utf-8 ", Url: action, datatype: 'html', success: function (date ) {$ (DataContainer) .html (data); $ (What) .hide ();}   

My MVC action:

  public PartialViewResult GetAvailability (FormModel frmData) {var vm = Bll.GetAvailabilityWithHolds (frmData.txtlitm, frmData.txtmcu, frmData.txtlocn); return PartialView (new GetAvailabilityModel {availability = VM});}   

My form class:

  Public class FormModel {public string txtlitm {get; Set; } Public string txtmcu {get; Set; } Public string txtlocn {get; Set; }}   

Whatever I do, I get zero values ​​in the controller's action.

What am I doing wrong?

Have you tried this? You do not need to use Jason, you can get standard form encoding

  $. Ajax ({type: "POST", can go with data: $ ('# frmUserData').), URL: Action, Data Type: 'html', Success: Function (Data) {$ (DataConnator). Html (data); I can not test any of these improvements, but about trying to fix my original solution: <$ < / P> 

Effort 1

  $ Ajax ({type: "POST", data: '{ "frmData":' + JSON.stringify ($ ( '$ frmUserData'). SerializeArray () [0]) + '}', content type "application / Jason ; Charset = UTF-8 ", url: action, data type: 'html', success: function (data) {$ (dataconator). Html (data); $ (what) .hide ();}   

Try 2

  $. Ajax ({type: "POST", data: JSON.stringify ($ ( '$ frmUserData'). SerializeArray () [0] ), ContentType: "application / json; charset = utf-8", url: action, datatype: 'html', success: function (data) {$ (datacontenter) .html (data); $ (what) );}    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -