.NET MVC Web Forms

MIS 324

BigWebFormModel.cs

using System.ComponentModel.DataAnnotations;

namespace mis324LectureExamples.Models

{

publicclassBigWebFormModel

{

[Required]

[Display(Name="First Name")]

publicstring FName { get; set; } //textbox

[Required]

publicstring Gender { get; set; } // radioButtonList

[Required]

publicDateTime BirthDate { get; set; } //textbox

[Display(Name="Seahawk Fan?")]

publicbool IsSeaHawkFan { get; set; } //checkbox

[Display(Name="Sonics Fan?")]

publicbool IsSonicsFan { get; set; } //checkbox

publicint PersonId { get; set; } //hidden

}

}

BigWebFormController.cs

using mis324LectureExamples.Models;

using mis324LectureExamples.ViewModels.BigWebFormViewModel;

namespace mis324LectureExamples.Controllers

{

publicclassBigWebFormController : Controller

{

// GET: BigWebForm

[HttpGet]

publicActionResult Index()

{

Response.Write("Method Get <br>");

//set a couple of form values

BigWebFormModel bwf = newBigWebFormModel();

bwf.PersonId = 6;

bwf.IsSeaHawkFan = true;

return View(bwf);

}

[HttpPost]

publicActionResult Index(BigWebFormModel bwf)

{

if (ModelState.IsValid)

{

ViewBag.message = bwf.FName + " is a " + bwf.Gender.ToLower() + " who was born " +

bwf.BirthDate.ToShortDateString() + ". ";

ViewBag.message += "PersonId:" + bwf.PersonId + " IsSeaHawkFan: " +

bwf.IsSeaHawkFan + "";

}

return View(bwf);

}

}

}

Index.cshtml

@model mis324LectureExamples.Models.BigWebFormModel

@using mis324LectureExamples.ViewModels.BigWebFormViewModel

@{

ViewBag.Title = "Index";

}

h2Index</h2

@using (Html.BeginForm())

{

@Html.AntiForgeryToken()

divclass="form-horizontal">

h4BigWebFormModel</h4

hr/>

@Html.ValidationSummary(true, "", new { @class = "text-danger" })

divclass="form-group">

@Html.LabelFor(model => model.FName, htmlAttributes: new { @class =

"control-label col-md-2" })

divclass="col-md-10">

@*Need to use textbox helper to add autofocus*@

@Html.TextBoxFor(model => model.FName, new { htmlAttributes = new { @class =

"form-control" }, autofocus = "autofocus" })

@Html.ValidationMessageFor(model => model.FName, "", new { @class =

"text-danger" })

</div

</div

divclass="form-group">

@Html.LabelFor(model => model.Gender, htmlAttributes: new { @class =

"control-label col-md-2" })

divclass="col-md-10">

@Html.RadioButtonFor(m => m.Gender, "Male") Malebr/>

@Html.RadioButtonFor(m => m.Gender, "Female") Female

@Html.ValidationMessageFor(model => model.Gender, "", new { @class =

"text-danger" })

</div

</div

divclass="form-group">

@Html.LabelFor(model => model.BirthDate, htmlAttributes: new { @class =

"control-label col-md-2" })

divclass="col-md-10">

@*Need to use textbox helper for type = date*@

@Html.TextBoxFor(model => model.BirthDate, new { htmlAttributes =

new { @class = "form-control" }, type = "date"})

@Html.ValidationMessageFor(model => model.BirthDate, "", new { @class =

"text-danger" })

</div

</div

divclass="form-group">

divclass="col-md-2"</div

divclass="col-md-10">

divclass="checkbox">

@Html.EditorFor(model => model.IsSeaHawkFan) Seahawk Fan?br/>

@Html.EditorFor(model => model.IsSonicsFan) Sonics Fan?

@Html.HiddenFor(model => model.PersonId)

</div

</div

*** truncated here *****