Reputation: 13818
How do I do validation in mvc if I'm not using models?
I'm directly obtaining data from the controller and displaying it.
How do I validate? Most examples seem to use the model to validate.
Upvotes: 0
Views: 512
Reputation: 21991
I think you might want to have [AcceptVerbs(HttpVerbs.post)] in your code:
class TestController : Controller
{
[AcceptVerbs (HttpVerbs.Post)]
public ActionResult SomeAction (FormCollection form)
{
if (MyCustomValidation (form))
SaveData ();
RedirectToAction ("SomeAction");
}
}
Upvotes: 1
Reputation:
Although it is considered to be against MVC paradigm, nothing technically prevents you from working with the posted form directly.
class TestController : Controller
{
[AcceptVerbs (HttpVerbs.Post)]
public ActionResult SomeAction (FormCollection form)
{
if (MyCustomValidation (form))
SaveData ();
RedirectToAction ("SomeAction");
}
}
Upvotes: 2
Reputation: 18220
You could use a service layer as described by this article, this allows both separation of concerns whilst maintaining error handling, not relying on the controller to do it all for you.
Upvotes: 0