I have a really odd issue with ASP.Net MVC.
I have a form, which is posting 3 text values to an action method called create user (for simplicity sake, say it is the following);
public ActionResult CreateUser(string FirstName, string LastName, string Email)
{
var s = FirstName + LastName + Email;
return RedirectToAction("Index");
}
Say also my form is
<% using (Html.BeginForm("CreateUser", "User"))
{ %>
<%=Html.TextBox(("FirstName")) %>
<%=Html.TextBox(("LastName")) %>
<%=Html.TextBox(("Email")) %>
<div><input type="submit" value="Submit" /></div>
<% } %>
Now in my action method, on the user controller, the values FirstName, LastName and Email are all null!
However, if I copy the same method to another controller (Game), and update the form to post there, the values in the method are not null! I am totally stumped with this one.
Both Controllers are the same - they inherit the same base class, have the same attributes applied to them etc.
EDIT: Got it working (not sure what the underlying issue was).
I had a custom attribute on my Index method on the User controller (this essentially parsed the HttpContext.Current.User.Identity.Name property and automatically passed it into the method). For some reason, this was problematic on the Index method, once I removed it everything started working as intended!
This was my Index method before:
[Authorisation]
public Action Index(string userName){...}
and after
public Action Index() {...}