Reputation: 65
<form method="post" id="modalForm" action="/Test/TestForm" target="myframe">
<input type="text" name="id" required />
<input type="text" name="name" required />
<input type="submit" value="Post" onsubmit="alert('after post!');" />
</form>
[HttpPost]
public IActionResult TestForm(Test test)
{
return View();
}
public class Test
{
public string id;
public string name;
}
What needs to be changed, on the form, to get values to the Test class? Currently the values are null? I would like to keep it simple, without ASP.NET Core helpers.
Upvotes: 1
Views: 712
Reputation: 1228
C# provides a way to use short-hand / automatic properties where you only have to write get;
and set;
inside the property.
public class Test
{
public string id { get; set; }
public string name { get; set; }
}
Upvotes: 1