jquery - Internal server error while processing AJAX request in MVC5 -


I have something inside a MVC 5 app and my _Layout.cshtml file like this:

  & lt; Div class = "input-top" & gt; & Lt; One class = "gobtn" href = "" & gt; & Lt; Img src = "~ / content / img / GOBtn.png" class = "gobtn-position" & gt; & Lt; / A & gt; & Lt; Input id = "homezip code" type = "text" class = "form-control input-position-2" placeholder = "zip" & gt; & Lt; Input id = "home system" type = "text" class = "form-control input-position-1" placeholder = "What do you need to do today?" & Gt; & Lt; / Div & gt;   

And the point is that when the user fills the above input and presses the href attribute, then I want to open a new watch page and send the data with the view. The verb method that is related to the vision is defined as:

  [authorized] public action service request () {...} [authorize] [http post] [legitimate antifreeze token ] Public Action Service Requests (Requests View Modell RVM, HTTPPosted FileBase Image = Faucet, HppstatedFilebase Video = Faucet) {...}   

My RVM visualization model is defined as following: < / P>

  Public Square RequestViewModel {[Required (error message = "Please select state")] [Display (name = "state")] Public int StateID {Received; Set; } [Required (error message = "Please enter a zip code")] [Display (name = "zip")] Public string zipcode {received; Set; } [Required (Error Message = "Please Choose a Service")] [Display (name = "Service")] Public String ServiceName {get; Set; } // More under unrelated fields}   

Finally, I have my AJAX call, in which I have defined the script tags in my _Layout.cshtml file:

  & lt; Script & gt; $ (Document) .ready (function () () ($ ('a.GoBtn'). ('Click', function (e) {e.preventDefault (); debugger; // Submit an AJAX post request with data Home Homezipcode = $ ("# homezipcode"). Val (); var HomeServices = $ ("# HomeSystem"). Val (); var model = {zipcode: homezip code, savannum: home service}; $ .ajax ({url} : '@ Url.Action ("ServiceRequest", "Home"), Content Type:' Application / Jason; Charset = UTF-8 ', Type:' Post ', Data Type:' html ', Data: JSON.stringify Model)}) .success (function (result) {});});}); & Lt; / Script & gt;   

The problem is, when I fill those two input fields, and press the Go href, I get an error message:

The postal localhost : 44300 / Home / Service Request [HTTP / 1.1 500 Internal Server Error 4ms]

What can be any problem? And how to solve it?

On your action you have valid antifurrency token attribute method but AJAX call The token is not passing. Remove the feature and it will work.

Alternatively, you must include an anti-forgery token in AJAX POST by entering a @ html.AnttiForgeryToken () on your page, then including the value in which this hidden input it happens.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -