как передать один-ко-многим из контроллера для просмотра в mvc4
Итак, это будет после изменений, с которыми вы, ребята, помогли мне, я предполагаю, что я где-то получаю синтаксическую ошибку
Посмотреть
@model OilNGasWeb.ModelData.Clients
@{
ViewBag.Title = "Index";
}
County's for
<p>
@Html.ActionLink("Create New", "Create",new { id = Model.ClientID },null)
</p>
@Html.DisplayNameFor(model => model.County)
@Html.DisplayNameFor(model => model.Note)
@Html.DisplayNameFor(model => model.Comment)
@foreach (var item in Model.Countys) {
@Html.DisplayFor(modelItem => item.County)
@Html.DisplayFor(modelItem => item.Note)
@Html.DisplayFor(modelItem => item.Comment)
@Html.ActionLink("Edit", "Edit", new { id=item.CountyID })
@Html.ActionLink("Details", "Details", new { id=item.CountyID })
@Html.ActionLink("Delete", "Delete", new { id=item.CountyID })
}
Клиенты модели
[Table("Clients")]
public class Clients
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int ClientID { get; set; }
public string Client { get; set; }
public string Address { get; set; }
public string State { get; set; }
public string City { get; set; }
public string County { get; set; }
public int Zip { get; set; }
public string Phone { get; set; }
public string LogoLocation { get; set; }
public string ContactName { get; set; }
public string ContactPhone { get; set; }
public string ContactEmail { get; set; }
public int Authorized { get; set; }
public string Note { get; set; }
public string Comment { get; set; }
public virtual ICollection Countys { get; set; }
}
Модель Граф
[Table("Countys")]
public class Countys
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int CountyID { get; set; }
public int ClientID { get; set; }
public string County { get; set; }
public string Note { get; set; }
public string Comment { get; set; }
public virtual ICollection Townships { get; set; }
}
Графический контроллер
public ActionResult Index(int id)
{
var cnty = from r in db.Clients
where r.ClientID == id
select r;
if (cnty != null)
{
return View(cnty); // View returns an error here
}
return HttpNotFound();
View возвращает ошибку, но я не могу зайти в нее ... чтобы выяснить, что это ... идеи?