Reputation: 103487
Currently the way I am handling postbacks in ASP.NET MVC is to grab the input variables using:
string username = "";
if (null != Request["username"])
username = Request["username"].ToString();
I then would run a regex on the variable to ensure it was valid.
Is there any other method for doing this?
Upvotes: 1
Views: 808
Reputation: 180914
ASP.NET MVC does Request-To-Object mapping automatically, through ModelBinders. An older article is here, under "Form Post and Model Binder Improvements", and there is a video here.
Upvotes: 1
Reputation:
You can handle the form inputs in your Action this way:
public ActionResult Create(string username)
{
// use
}
but you need to set your Route:
routes.MapRoute(
"Default", // Route name
"Create/{username}", // URL with parameters
new { controller = "YourController", action = "Create", username = "" } // Parameter defaults
);
Or you can use ModelBinders
Upvotes: 1