Skip to content

Instantly share code, notes, and snippets.

@mgroves
Created June 18, 2011 02:50
Show Gist options
  • Select an option

  • Save mgroves/1032749 to your computer and use it in GitHub Desktop.

Select an option

Save mgroves/1032749 to your computer and use it in GitHub Desktop.
[HttpPost]
public ActionResult Edit(int id, MyNameEntity name)
{
if(!ModelState.IsValid)
{
return View(name);
}
return RedirectToAction("Index");
}
using System.ComponentModel.DataAnnotations;
namespace MyProject.Web.Models.Entities
{
public class MyNameEntity
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public NameGroup? Group { get; set; }
[Required]
public string Prop1 { get; set; }
public string Prop2 { get; set; }
}
}
@codelinq
Copy link
Copy Markdown

When I renamed "name" to "test" it didn't return null anymore.

    [HttpPost]
    public ActionResult Edit(int id, MyNameEntity test)
    {
        if (!ModelState.IsValid)
        {
            return View(test);
        }
        return RedirectToAction("Index");
    }

    public ActionResult Edit(int id)
    {
        return View();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment