我有2个表我尝试的是在最后一个div中,CategoryName是一个DrobDown列表,其中包含我已插入的名称...如何获取此数据?如果有关代码的内容不清楚,我会解释 这是我的模特:
public class Profits
{
[Key]
public int id { get; set; }
public double Value { get; set; }
public string Description { get; set; }
public DateTime DateCreation { get; set; }
public ProfitCategories CategoryName { get; set; }
}
}
这是我的控制者:
public ActionResult DoInsertProf(Profits profits)
{
var Profit = new Profits
{
CategoryName = profits.CategoryName,
Value = profits.Value,
DateCreation = DateTime.Now,
Description = profits.Description,
};
db.Profit.Add(profits);
db.SaveChanges();
return Redirect("/SelectData/ReadProfit");
}
这是我的观点:
@using (Html.BeginForm("DoInsertProf","InsertProfit"))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Profits</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Value)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Value)
@Html.ValidationMessageFor(model => model.Value)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.CategoryName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.CategoryName)
@Html.ValidationMessageFor(model => model.CategoryName)
</div>
答案 0 :(得分:0)
您的问题真的不明确,而且您的代码无效......您是否尝试加载填充了DropDown的表单或在执行保存后显示某些结果?