ビューにいくつかのプロパティを渡そうとしていますが、間違ったプロパティが表示されます。モデルは次のとおりです。
public class ModuleDetails {
public long Id { get; set; }
public string ModuleId { get; set; }
public string TypeName { get; set; }
public string KindName { get; set; }
public IEnumerable<Property> Properties { get; set; }
}
public class Property {
public string Name { get; set; }
public string Value { get; set; }
}
これは私がコントローラーで行ったことです:
public ActionResult Details(long id) {
var ownerId = _dbSis.OwnedModules.Find(id);
var ownerName = _dbSis.Set<BusinessUnit>().Find(ownerId.ModuleOwnerId);
var module = (_dbSis.Modules.Select(m => new ModuleDetails {
Id = id,
ModuleId = m.ModuleId,
TypeName = m.ModuleType.TypeName,
KindName = m.ModuleType.ModuleKind.KindName,
Properties = m.PropertyConfiguration.PropertyInstances.Select(
x => new Property {Name = x.Property.Name, Value = x.Value})
}));
return View(module.FirstOrDefault());//am i doing something wrong here?
}
とビュー:
@using BootstrapSupport
@model AdminPortal.Areas.Hardware.Models.ModuleDetails
@{
ViewBag.Title = "Details";
Layout = "~/Views/shared/_BootstrapLayout.basic.cshtml";
}
<fieldset>
<legend>Module <small>Details</small></legend>
<dl class="dl-horizontal"> <!-- use this class on the dl if you want horizontal styling http://twitter.github.com/bootstrap/base-css.html#typography class="dl-horizontal"-->
<dt>ID</dt>
<dd>@Model.Id</dd>
<dt>Module ID</dt>
<dd>@Model.ModuleId</dd>
<dt>Module Type</dt>
<dd>@Model.TypeName</dd>
<dt>Module Kind</dt>
<dd>@Model.KindName</dd>
@foreach (var properties in Model.Properties)
{
<dt>Property Names</dt>
<dd>@properties.Name</dd>
<dt>Property Value</dt>
<dd>@properties.Value\</dd>
}
</dl>
</fieldset>
<p>
@Html.ActionLink("Edit", "Edit", Model.GetIdValue()) |
@Html.ActionLink("Back to List", "ModuleList")
</p>
プログラムを実行し、コントローラーのアクションでブレークポイントを設定すると、これが得られます
プロパティに名前と値があることがわかります。しかし、ビューでは、選択したアイテムに関係なく常に最初のアイテムの詳細を取得しますが、ID は Id i が選択した Id です。やってるからかな
return View(module.FirstOrDefault());
正しいアイテムとそのプロパティを View に渡すにはどうすればよいですか?