noroozifar
پنج شنبه 07 فروردین 1393, 02:09 صبح
سلام
دارم mvc را یاد میگیرم و بیشتر از فیلم ها استفاده کرده ام تا پی دی اف حالا سئوال اینه به چه طریق میشه چند مدل را به سمت ویو فرستاد مثلا الان یک کنترل مربوط به ایندکس که یک مدل را میفرسته به سمت ویو :
public ActionResult Index(string searchTerm=null,int page=1)
{
var model = (from r in _db.Restaurants
orderby r.Name ascending
where r.Name.StartsWith(searchTerm) || searchTerm==null
select r).ToPagedList(page,10);
return View(model);
}
و این هم ویو آن هستش :
@model IEnumerable<OdeToFood.Models.Restaurant>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@if(User.IsInRole("Admin")){
@Html.ActionLink("Create New", "Create")}
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.city)
</th>
<th>
@Html.DisplayNameFor(model => model.country)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.city)
</td>
<td>
@Html.DisplayFor(modelItem => item.country)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.id }) |
@Html.ActionLink("Reviews", "Index","Reviews", new { id=item.id },null) |
@Html.ActionLink("Delete", "Delete", new { id=item.id })
</td>
</tr>
}
</table>
حالا اگر ما دو تا مدل داشته باشیم به این صورت ذیل باید به چه صورت بفرستیم به ویو و به چه صورت در ویو نمایش دهیم :
public ActionResult Index(string searchTerm=null,int page=1)
{
var model1 = (from r in _db.Restaurants
orderby r.Name ascending
where r.Name.StartsWith(searchTerm) || searchTerm==null
select r).ToPagedList(page,10);
var model2 = (from r in _db.Restaurants
orderby r.Name ascending
select r).ToPagedList(page, 10);
return View(؟);
}
دارم mvc را یاد میگیرم و بیشتر از فیلم ها استفاده کرده ام تا پی دی اف حالا سئوال اینه به چه طریق میشه چند مدل را به سمت ویو فرستاد مثلا الان یک کنترل مربوط به ایندکس که یک مدل را میفرسته به سمت ویو :
public ActionResult Index(string searchTerm=null,int page=1)
{
var model = (from r in _db.Restaurants
orderby r.Name ascending
where r.Name.StartsWith(searchTerm) || searchTerm==null
select r).ToPagedList(page,10);
return View(model);
}
و این هم ویو آن هستش :
@model IEnumerable<OdeToFood.Models.Restaurant>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@if(User.IsInRole("Admin")){
@Html.ActionLink("Create New", "Create")}
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.city)
</th>
<th>
@Html.DisplayNameFor(model => model.country)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.city)
</td>
<td>
@Html.DisplayFor(modelItem => item.country)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.id }) |
@Html.ActionLink("Reviews", "Index","Reviews", new { id=item.id },null) |
@Html.ActionLink("Delete", "Delete", new { id=item.id })
</td>
</tr>
}
</table>
حالا اگر ما دو تا مدل داشته باشیم به این صورت ذیل باید به چه صورت بفرستیم به ویو و به چه صورت در ویو نمایش دهیم :
public ActionResult Index(string searchTerm=null,int page=1)
{
var model1 = (from r in _db.Restaurants
orderby r.Name ascending
where r.Name.StartsWith(searchTerm) || searchTerm==null
select r).ToPagedList(page,10);
var model2 = (from r in _db.Restaurants
orderby r.Name ascending
select r).ToPagedList(page, 10);
return View(؟);
}