Take the 2-minute tour ×

I am using MVC and have a view (test.cshtml) that contains a form. Is there a way to send it to another View page.cshtml for testing instead of same [http] controller ActionResult test()?

I am trying to validate that all the form field values are correct before updating db. Is there an easier way to do this?

share|improve this question
you can send it to another ActionResult with some other name in the same controller. –  TheNewOne Feb 21 '13 at 10:36
There is an easier way to do that, just put all your validation in your model, then call ModelState.IsValid before you save. You can make a form post to whatever controller/action you like by specifying them as parameters in the Html.BeginForm call –  mattytommo Feb 21 '13 at 10:38
add comment

1 Answer

up vote 0 down vote accepted

In your view

@using (Html.BeginForm("Add", "Weight", FormMethod.Post))    
//where "Add" is the Action name and Weight is the controller (WeightController) -> http://foo/Weight

With a model

public class WeightModel
    [Required] public string Description { get; set; }
    [Required] public int Weight { get; set; }
    public string Notes { get; set; }

In your Controller

    public ActionResult Add(WeightModel model)
        if (!ModelState.IsValid) //framwork will validate based on attributes on model
            return View("Index", model);
            //save to db
            return RedirectToAction("Added");
share|improve this answer
add comment

Your Answer


