Класс контроллера:
public class PlantHeadController : Controller
{
private WOMSEntities2 db = new WOMSEntities2();
//
// GET: /PlantHead/
public ActionResult Index()
{
ViewBag.productCode = new SelectList(db.Product, "ID","code");
return View();
}
public ActionResult printReceipt(PlantHeadInfo plantHeadInfo)
{
ViewBag.name = plantHeadInfo.productManagerName;
ViewBag.pCode = plantHeadInfo.productCode;
int p = plantHeadInfo.productCode;
ViewBag.WareHouseDescription = new SelectList(db.WareHouse, "Description", "Description");
/// ViewBag.WareHouseDescription = plantHeadInfo.WareHouseDescription;
ViewBag.amount = plantHeadInfo.amount;
ViewBag.minQuantity = db.ProductFormulation.Where(r => r.ProductID == 1);
ViewBag.pc = db.Product.Where(r => r.ID == p).Single().Code;
var results = db.ProductFormulation.Where(r => r.ProductID == p);
ViewBag.rawMaterial = db.ProductFormulation.Where(r => r.ProductID == 1);
ViewBag.chetan=db.Product;
//, пожалуйста, помогите мне в следующем коде, в этом я хочу получить доступ к значению поля кода // RawMaterial Table, где ProductID = 1 в таблице продуктов.
ViewBag.res = (from x in db.RawMaterial join y in db.ProductFormulation on x.ID equals y.RawMaterialID where y.ProductID == 1 select y.Code);
return View();
}
}
View
@model IEnumerable<CalcoWOMS.Models.ProductFormulation>
@{
ViewBag.Title = "Generate Receipt";
Layout = "~/Views/Shared/_firstLayout.cshtml";
}
<h2>Index</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend></legend>
<div class="editor-label">
@Html.Label("Product Manager")
</div>
<div class="editor-field">
@ViewBag.name
</div>
<div class="editor-label">
@Html.Label("productCode")
</div>
<div class="editor-field">
@ViewBag.pCode
</div>
<div class="editor-label">
@Html.Label("WareHouse")
</div>
<div class="editor-field">
@Html.DropDownList("WareHouseDescription", "SELECT")
</div>
<div class="editor-label">
@Html.Label("Quantity")
</div>
<div class="editor-field">
(@ViewBag.amount)
</div>
<div class="editor-label">
@Html.Label("Checking")
</div>
<div class="editor-field">
(@ViewBag.pc)
</div>
<div>
hello
@foreach(var album in @ViewBag.rawMaterial)
{
<h2>@album.RawMaterialID</h2>
}
</div>
<div>
<!-- help me here what should i write here below code to use res which is sent from controller-->
@foreach(var album in ViewBag.res)
{
<h2>@album</h2>
}
</div>
<p>
<input type="submit" value="Print Receipt" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>