- Update Navigation Properties with Entity Framework (MVC3 Razor)
- @model PDR.Models.RateProfile
- @using (Html.BeginForm()) {
- @Html.ValidationSummary(true)
- <fieldset>
- <legend>RateProfile</legend>
- @Html.HiddenFor(model => model.RateProfileID)
- @Html.HiddenFor(model => model.LoginID)
- <div class="editor-label">
- @Html.LabelFor(model => model.ProfileName)
- </div>
- <div class="editor-field">
- @Html.EditorFor(model => model.ProfileName)
- @Html.ValidationMessageFor(model => model.ProfileName)
- </div>
- <div class="editor-label">
- @Html.LabelFor(model => model.isDefault)
- </div>
- <div class="editor-field">
- @Html.EditorFor(model => model.isDefault)
- @Html.ValidationMessageFor(model => model.isDefault)
- </div>
- <div>
- <fieldset>
- <legend>Dime</legend>
- <table>
- <tr>
- <th>
- Min
- </th>
- <th>
- Max
- </th>
- <th>
- Price
- </th>
- <th></th>
- </tr>
- @foreach (var rate in Model.Rates)
- {
- <tr>
- <td>
- @Html.EditorFor(modelItem => rate.minCount)
- @Html.ValidationMessageFor(model => rate.minCount)
- </td>
- <td>
- @Html.EditorFor(modelItem => rate.maxCount)
- @Html.ValidationMessageFor(model => rate.maxCount)
- </td>
- <td>
- @Html.EditorFor(modelItem => rate.Amount)
- @Html.ValidationMessageFor(model => rate.Amount)
- </td>
- </tr>
- }
- </table>
- </fieldset>
- <p>
- <input type="submit" value="Save" />
- </p>
- </fieldset>
- }
- [HttpPost]
- public ActionResult Edit(RateProfile rateprofile)
- {
- if (ModelState.IsValid)
- {
- db.Entry(rateprofile).State = EntityState.Modified;
- foreach (Rate rate in rateprofile.Rates)
- {
- db.Entry(rate).State = EntityState.Modified;
- }
- db.SaveChanges();
- return RedirectToAction("Index");
- }
- return View(rateprofile);
- }
- public partial class Rate
- {
- public int RateID { get; set; }
- public int RateProfileID { get; set; }
- public string Size { get; set; }
- public decimal Amount { get; set; }
- public int minCount { get; set; }
- public int maxCount { get; set; }
- public int PanelID { get; set; }
- public virtual Panel Panel { get; set; }
- public virtual RateProfile RateProfile { get; set; }
- }
- public partial class RateProfile
- {
- public RateProfile()
- {
- this.Rates = new HashSet<Rate>();
- }
- public int RateProfileID { get; set; }
- public string ProfileName { get; set; }
- public int LoginID { get; set; }
- public bool isDefault { get; set; }
- public virtual Login Login { get; set; }
- public virtual ICollection<Rate> Rates { get; set; }
- }
- @for (var int i = 0; i < Model.Rates; i++)
- {
- <tr>
- <td>
- @Html.EditorFor(modelItem => Model.Rates[i].minCount)
- @Html.ValidationMessageFor(model => Model.Rates[i].minCount)
- </td>
- <td>
- @Html.EditorFor(modelItem => Model.Rates[i].maxCount)
- @Html.ValidationMessageFor(model => Model.Rates[i].maxCount)
- </td>
- <td>
- @Html.EditorFor(modelItem => Model.Rates[i].Amount)
- @Html.ValidationMessageFor(model => Model.Rates[i].Amount)
- </td>
- </tr>
- }