last day (14 days later) » 

11:47 AM
0
Q: Internal server error while processing AJAX request in MVC5

ettI have an MVC 5 app, and inside my _Layout.cshtml file, I have something like this: <div class="input-top"> <a class="GoBtn" href=""><img src="~/Content/img/GOBtn.png" class="gobtn-position"></a> <input id="homeZipCode" type="text" class="form-control input-position-2" placeholder=...

 
ett
@christiandev I tried, it doesn't work, same error.
@SSA Yes, but the point is that I want to open my ServiceRequest view, and in the ZipCode and ServiceName fields I want to have the data presented from the above input fields. The other inputs I want to be empty, and let the user fill them.
 
Shouldn't you also be passing StateID in the POST data?
 
ett
@DavidG But, I just want to open the view, and in the fields for ZipCode and ServiceName, I want the data from the above inputs to be present, then let the user fill out the other fields.
 
But StateID is marked as [Required]
 
ett
@DavidG Okay, I changed it to: var model = { StateID: 1, ZipCode: homeZipCode, ServiceName: homeService };, but I still get the same error message.
 
11:47 AM
And what happened??????
 
ett
@DavidG Nothing, everything the same, same error message in console, same output for the debugger, as in the pic that I posted above.
 
Then you need to check the full response of the error from the server, so not just the HTTP500 error, but what is in the body of that response
 
ett
Where can I find that information exactly?
 
Are you using IE or Chrome?
 
ett
firefox
but I can change to chrome
 
11:48 AM
Just need to remember how to use Firefox!
Of course it has to update on my PC...
 
ett
tell me for chrome, I will try it there :) no problem for me
 
It's OK. In the network tab I think, it should show all requests made, click on the one that says 500 POST then select the response tab
 
ett
Okay, let me try
okay i got it, do you need any specific information from there?
 
Yeah, what is in the response
 
ett
The required anti-forgery cookie "__RequestVerificationToken" is not present.
HttpAntiForgeryException (0x80004005): The required anti-forgery cookie &quot;__RequestVerificationToken&quot; is not present.]
 
11:58 AM
So remove ValidateAntiForgeryToken attribute from the action method
 
ett
Now I get an error message in the console saying: no element found, and response in network tab i sempty
empty*
 
Is it running your action now?
 
ett
I get 200 status code in network
no element found error in console, and the page is not redirecting or something
 
Can you give a screenshot?
 
ett
i simply want when the go button is pressed the ServiceRequest view to be opened with the data from the inputs that I give.
well, this is my service request page
this is in my homepage, when i fill those inputs and press go
One more thing, my ServiceRequest view requires authorization in order to display it or to submit the form, the results that I show you is if the user is not authorized
this is if the user is logged-in
it shows error in this line:
var list = results.OrderBy(b => Math.Abs(Convert.ToInt32(rvm.ZipCode) - Convert.ToInt32(b.Zip))).Take(5).ToList();
 
12:09 PM
ok so the original question is now answered, this is a new problem
 
ett
I guess so, but one question, why it shows 200 when the user is not logged in?
 
You sure nobody is logged in?
 
ett
yes, when nobody is logged-in it shows 200, but i need it to redirect to log-in page
when a user is logged-in it shows the message above with 500 status code
and the response is empty when no user is logged-in
 
Are you checking user in the action method?
 
ett
[Authorize]
public ActionResult ServiceRequest()
{
ViewBag.StateID = new SelectList(db.States, "StateID", "StateName");
return View();
}

[Authorize]
[HttpPost]
public ActionResult ServiceRequest([Bind(Include = "StateID,ZipCode,ServiceName,ImageData,ImageMimeType,VideoData,VideoMimeType")]RequestViewModel rvm, HttpPostedFileBase image = null, HttpPostedFileBase video = null)
normally if i want to open the ServiceRequest view, it asks me to log-in in order to display the view, which seem that authorize works
 
12:15 PM
Let me post answer to your original question, then we can keep chatting about this new one.
 
ett
Okay.
 
Thanks for the accept :)
Might help with your new issue
Or at least one of them!
 
ett
I will take a look at it. and about the other issue, with linq to entites, i guess i need to post a new question for it.
 
Yeah, or Google it, it looks like it's a pretty thing people come across.
 
ett
Okay thanks for everything.
 
12:27 PM
No problem
 

last day (14 days later) »