HttpContext.Request.Form threw an exception of type 'System.InvalidOperationException' - why?
HttpContext.Request.Form threw an exception of type 'System.InvalidOperationException' - why?
I have a strange problem. We are using C# for an ASP.NET MVC application, and JavaScript with jQuery and Data Tables for the frontend. In the frontend, a part of the code looks like this:
table: "#restapiusers",
ajax: {
create: { url: "/restapiuser/RegisterUser" },
edit: { url: "/restapiuser/EditUser" }
},
The thing is that although both endpoints RegisterUser and EditUser get passed the payload in the same manner, only EditUser works.
[HttpPost]
public async Task<JsonResult> RegisterUser(RestApi_UserModel user_short)
{
var param = HttpContext.Request.Form.Keys.FirstOrDefault();
When I set a breakpoint to the above line and move the mouse cursor over "Form", it says that HttpContext.Request.Form threw an exception of type 'System.InvalidOperationException'.
The beginning of EditUser looks exactly the same and there the error does not occur. I am puzzled how this is possible.
Answers
An observation: In RegisterUser HttpContext.Request.HasFormContentType = false. In EditUser it is true.
I commented out the lines I marked with "***" and now it works.
Is this using Editor? Otherwise, it doesn't sound like a DataTables issue, so would be worth asking on StackOverflow or a site specific to .NET.
Colin
Yes, it is about Editor. As I have already stated it is solved now.
I was querying as our accounts aren't showing that you have a license - is the license registered to another email address? Please can let us know so we can update our records.
Colin
Our company has a license. I am registered with my private email address.
Many thanks for the update. Great to hear you've got it resolved now
Allan