[英]How to get the value of 1st row “Name” from partial view when page first loads in parent view?
當頁面首次加載到父視圖中時,我想從部分視圖中獲取第一行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>
如果要從第一個局部視圖中靜態地選擇第一行,可以在視圖中嘗試以下代碼Model.firsts().FirstOrDefault().Name
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.