Im пытается заполнить данные в представлении из sql db. Я выбираю все рецепты из определенной страны ... O.k ... Я также хочу отобразить название страны в верхней части представления, но у меня возникают проблемы с возвратом результата в представление. Любые идеи, было бы весьма признателен ...вернуть правильные данные в mvc View
Heres мой код
@model IEnumerable<FoodB.recipeTbl>
<h2>************where i want to put the country title***************88</h2>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.recipe_title)
</th>
<th>
@Html.DisplayNameFor(model => model.ingredients)
</th>
<th>
@Html.DisplayNameFor(model => model.country_id)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.recipe_title)
</td>
<td>
@Html.DisplayFor(modelItem => item.ingredients)
</td>
<td>
@Html.DisplayFor(modelItem => item.country_id)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.id }) |
@Html.ActionLink("Details", "Details", new { id=item.id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.id })
</td>
</tr>
}
</table>
Вот мой контроллер
public ActionResult Index(int id)
{
//select all recipes for country
var query = db.recipeTbls.Where(c => c.country_id == id);
//get country from country table*******how to return this***********
var ctry = db.countryTbls.Where(country => country.id == id);
return View(query);
}
только для того, чтобы просто указать название страны. Я передал бы имя через сумку для просмотра. –
Эй, это ... Пробовал. получение [...] [SELECT] [Extent1]. [country_id] FROM [dbo]. [recipeTbl] AS [Extent1] WHERE [Extent1]. [country_id] = @ p__linq__0 ,,,,, когда я выполняю var ctry = db.countryTbls.Where (country => country.id == Я бы); ViewBag.country = ctry.ToString(); // вернуть страну через сумку для просмотра –