Skip to content

Instantly share code, notes, and snippets.

@ArnisL
Created December 1, 2011 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArnisL/1416345 to your computer and use it in GitHub Desktop.
Save ArnisL/1416345 to your computer and use it in GitHub Desktop.
//view
@model StateIneligibilityModel
@Html.Js("ineligibilities/state")
@using (Html.BeginForm("State", "Ineligibilities", FormMethod.Post)){
<fieldset class="state-ineligibility">
<legend>State ineligibility:</legend>
@Html.HiddenFor(x=>x.Project)
<table>
<tr>
<td>@Html.LabelFor(x=>x.IneligibleCosts)</td>
<td>@Html.EditorFor(x=>x.IneligibleCosts)</td>
</tr>
<tr>
<td>@Html.LabelFor(x=>x.Type)</td>
<td>@Html.EditorFor(x=>x.Type)</td>
</tr>
<tr>
<td>@Html.LabelFor(x=>x.Partner)</td>
<td class="partner">@Html.EditorFor(x=>x.Partner)</td>
</tr>
<tr>
<td>@Html.LabelFor(x=>x.DiscoveredBy)</td>
<td>@Html.EditorFor(x=>x.DiscoveredBy)</td>
</tr>
<tr>
<td>@Html.LabelFor(x=>x.Explanation)</td>
<td class="explanation">@Html.EditorFor(x=>x.Explanation)</td>
</tr>
</table>
<input type="submit" value="State"/>
</fieldset>
}
//view model (using MvcExtensions for metadata configuration)
public class StateIneligibilityModel{
public decimal? IneligibleCosts { get; set; }
public IneligibilityType Type { get; set; }
public string Explanation { get; set; }
public int Project { get; set; }
public string Partner { get; set; }
public DiscovererInstitution DiscoveredBy { get; set; }
public Ineligibility AsIneligibility(){
return new Ineligibility(IneligibleCosts.Value,Type,Explanation,DiscoveredBy,Partner);
}
}
public class StateIneligibilityMeta:Meta<StateIneligibilityModel>{
public StateIneligibilityMeta(){
Configure(x=>x.IneligibleCosts)
.Required()
.DisplayName("Ineligible costs");
Configure(x=>x.Explanation)
.AsMultilineText()
.Required();
Configure(x=>x.DiscoveredBy)
.DisplayName("Discovered by")
.Required()
.AsDropDownList("discovererInstitutions");
Configure(x=>x.Partner)
.Required()
.AsDropDownList("partners");
Configure(x=>x.Type)
.Required()
.AsDropDownList("ineligibilityTypes");
}
}
}
//controller actions
[HttpGet]
public ActionResult State(int project){
return View(new StateIneligibilityModel {Project=project});
}
[HttpPost]
public ActionResult State(StateIneligibilityModel m){
var p=s.Load<Project>(m.Project);
return Do(()=>{
p.Ineligibilities.StateIneligibility(m.AsIneligibility());
return ToProject(m.Project)();},()=>View(m));
//that Do() is a bit awkward way to ensure validation and some other stuff. it's not relevant
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment