【发布时间】:2014-07-11 04:04:19
【问题描述】:
我有以下型号:
public partial class CityMaster
{
public int id { get; set; }
public string cityname { get; set; }
}
public partial class CityJourny
{
public int journyId { get; set; }
public int fromCity { get; set; } //foreign key from citymaster
public int ToCity { get; set; } //foreign key from citymaster
public string description { get; set; }
public string distance { get; set; }
}
//View model
public partial class VMCity
{
public CityMaster cm { get; set; }
public List<CityJourny> cj { get; set; }
}
cityview.cshtml:
@model APIModels.UserModel.VMCity
@{
ViewBag.Title = "View1";
}
<h2>View1</h2>
<fieldset>
<legend>VMCity</legend>
@Html.DisplayFor(model => model.cm.cityname)
@* hear I would like to display list of city from city *@
@Html.Partial("Partial1",new APIModels.UserModel.VMCity());
</fieldset>
<p>
@Html.ActionLink("Edit", "Edit", new { /* id=Model.PrimaryKey */ }) |
@Html.ActionLink("Back to List", "Index")
</p>
我应该在我的控制器操作中写什么来显示城市数据和城市距离列表以及详细信息(我们提供从一个城市到另一个城市的巴士服务)
【问题讨论】:
-
@Html.Partial("Action", "Controller",new APIModels.UserModel.VMCity()); -
@ ehsan sajjad例如我们有城市a,b,c,d的城市列表,我们提供从城市a到城市b和城市d所以当城市a被选中它将显示城市细节以及提供服务的城市列表
-
@Yuliam Chandra 在局部视图中我想显示模型 APIModels.UserModel.VMCity 我将显示城市数据列表
-
@sunny-kachwala,如果你的
Partial1.cshtml接受@model List<APIModels.UserModel.VMJourny>,那么你需要使用partial,如下@Html.Partial("Partial1", Model.cj)
标签: c# asp.net asp.net-mvc-4