我现在非常沮丧,这应该很容易做到,而且我尝试了很多不同的方法来做到这一点,但是由于某种原因,我似乎无法展示我的需要。我已经为此工作了几个小时,通常只是它
@if (ViewBag.NextPartNumber != null) { @ViewBag.NextPartNumber }
或
@Html.EditorFor(x => x.PartNextNumber, new { htmlAttributes =
new { @class="Form-control", @Value = Model.PartNextNumber }})
I在Dropdownlist
中选择一个选项,然后在选择该选项时会相应显示。
不知道为什么这些都不起作用,但是我在视图中有一个Model,并且在将其传递给视图时,该属性在Debug中已正确设置。我还尝试设置Viewbag
而不是我会满意的以太方式。这是我的代码,一堆我一直在尝试以任何方式显示它的ID感到满意。
控制器(如果您想让我的方法显示如何获得此信息,可以添加它,但请在此处更正)
public ActionResult TakeOutPart()
{
CreatePartBookSelectList();
CreateEnteredBySelectList();
CreateSoftwareTypeSelectList();
CreateSourceSelectList();
CreateManufacturerSelectList();
CreateDescriptionSelectList();
CreateUsageSelectList();
CreateUnitsSelectList();
// CreateMachineTypeSelectList();
var model = new PartNumberViewModel();
model.ListMachTypes = GetMachineTypes();
return View(model);
}
//[HttpPost, ActionName("TakeOutPart")]
public ActionResult TakeOutPartVM(PartNumberViewModel model)
{
CreatePartBookSelectList();
CreateEnteredBySelectList();
CreateSoftwareTypeSelectList();
CreateSourceSelectList();
CreateManufacturerSelectList();
CreateDescriptionSelectList();
CreateUsageSelectList();
CreateUnitsSelectList();
model.ListMachTypes = GetMachineTypes();
ViewBag.NextPartNumber = model.PartNextNumber;
return View("TakeOutPart", model);
} <div class="col-md-3 col-lg-3">
@*@if (ViewBag.NextPartNumber != null)
{
@foreach(var str in ViewBag.NextPartNumber)
{
<h6>
@str
</h6>
}
}*@
@* @Html.TextBox("txtNextPart", (string)@ViewBag.NextPartNumber,
new { @class = "form-control", @readonly = "readonly" })
}
else
{
@Html.TextBox("txtNextPart", null,
new { @class = "form-control", @readonly = "readonly" })
}*@
@Html.EditorFor(x => x.PartNextNumber, new { htmlAttributes =
new { @class="Form-control", @Value = Model.PartNextNumber }})
<br />
@Html.TextBox("lPartNextNumber", DateTime.Now.ToString() )
@Html.TextBox("lPartNextNumber", (string) @ViewBag.NextPartNumber )
<br />
@Html.TextBoxFor(c=>c.PartNextNumber)
<br /><br />
@Html.EditorFor(x => x.PartNextNumber, new { htmlAttributes =
new { @class="Form-control", @readonly="readonly" }})
<p>
(string) @ViewBag.NextPartNumber
</p>
</div>