0

我有 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>
4

1 回答 1

0

您的问题确实不清楚,并且您的代码无济于事...您是要加载填充了 DropDown 的表单还是在执行保存后显示一些结果?

于 2013-03-01T20:12:44.187 回答