RedirectToAction and validate MVC 2
Posted
by Dan
on Stack Overflow
See other posts from Stack Overflow
or by Dan
Published on 2010-03-26T22:16:55Z
Indexed on
2010/03/26
22:23 UTC
Read the original article
Hit count: 434
redirecttoaction
|validate
Hi,
my problem is the View where the user typed, the validation. I have to take RedirectToAction on the site because on the site upload a file. Thats my code.
My model class
public class Person
{
[Required(ErrorMessage= "Please enter name")]
public string name { get; set; }
}
My View
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcWebRole1.Models.Person>" %>
Name
<h2>Information Data</h2>
<%= Html.ValidationSummary() %>
<%using (Html.BeginForm ("upload","Home", FormMethod.Post, new{ enctype ="multipart/form-data" })) {%>
<fieldset>
<legend>Fields</legend>
<p>
<label for="name">name:</label>
<%= Html.TextBox("name") %>
<%= Html.ValidationMessage("name", "*") %>
</p>
</fieldset>
<% } %>
and the Controller
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult upload(FormCollection form)
{
Person lastname = new Person();
lastname.name = form["name"];
return RedirectToAction("Index");
}
Thx for answer my question In advance
© Stack Overflow or respective owner