vendredi 2 janvier 2015

How to use checkboxfor with db to dispaly db value with strong type

i'm a beginner.i'm try to use Html.CheckBoxFor to dispaly db value with strong type. this is my Question



  1. in create i don't know how to write

  2. after i select and post it, how to show it on Html.displayfor


Model:



public partial class Education
{
public int E_ID { get; set; }
public string Edu { get; set; }

public bool IsEdu { get; set; }

public Nullable<int> Disable { get; set; }
}


View Create:



@model MvcApplication4.Models.Education
@{
ViewBag.Title = "Create";
}

<h2>Create</h2>

@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<p>
@Html.CheckBoxFor(x => x.Education.IsEdu)
@Html.DisplayFor(x=>x.Education.Edu)

<input type="submit" value="Create" />
</p>
}


View Index:



@model IEnumerable<MvcApplication4.Models.TotalQues>

@{
ViewBag.Title = "Index";
}

<h2>Index</h2>
@Html.ActionLink("go to create", "Create")
@foreach (var item in Model)
{
@Html.DisplayFor(modelitem => item.Education.IsEdu)<br />
}




Aucun commentaire:

Enregistrer un commentaire