我希望在父视图中首次加载页面时从局部视图中获取第1行Name
的值。请建议我的方式。
模型
public class ClsA
{
public List<first> firsts{ get; set; }
public List<second> seconds{ get; set; }
}
public class first
{
public string Name { get; set; }
public string Address { get; set; }
}
public class second
{
public string Details{ get; set; }
public string Age{ get; set; }
}
控制器
public ActionResult ABC()
{
string name="abc";// currently I am passing value manually
SDetails sDetails=new SDetails();
var model = new ClsA();
model.firsts = sDetails.Rst();
model.seconds = sDetails.Rs(name); //I want to pass name value from 1st row of table
return View(model);
}
查看
@model Aplication.Models.ABC.ClsA
@{ Html.RenderPartial("_Partial", Model.firsts); }
@{ Html.RenderPartial("_PartialB", Model.seconds);}
PartialA
@model IEnumerable<Aplication.Models.ABC.first>
<table>
<tr>
<th>@Html.DisplayNameFor(m => m.Name)</th>
<th>@Html.DisplayNameFor(m => m.Address)</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Address)
</td>
</tr>
}
</table>
_PartialB
@model IEnumerable<Aplication.Models.ABC.second>
<table>
<tr>
<th>@Html.DisplayNameFor(m => m.Details)</th>
<th>@Html.DisplayNameFor(m => m.Age)</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Details)
</td>
<td>
@Html.DisplayFor(modelItem => item.Age)
</td>
</tr>
}
</table>
答案 0 :(得分:1)
如果您想要从第一个部分视图Model.firsts().FirstOrDefault().Name