ASP.NET MVC将单选按钮与文本框相结合



我正在创建用户将输入一些信息的表单。我正在使用EF将此信息存储到数据库中。我想在这里实现 3 个单选按钮。当用户选择第三个单选按钮(命名为"其他"(时,我想显示一些文本框,然后将此文本从文本框存储到数据库。我该怎么做?

我尝试了一些东西,但它只存储来自第三个单选按钮的数据库值,而不是从文本框存储。

@Html.RadioButtonFor(model => model.Type,"Material Master")
@Html.Label("Material Master")
@Html.RadioButtonFor(model => model.Type, "Packaging Master")
@Html.Label("Packaging Master")
@Html.RadioButtonFor(model => model.Type, "Other")
@Html.Label("Other")
@Html.EditorFor(m => m.Type, new { @disabled = "disabled", @class = "form-control" })

有人可以给我指路,怎么能做到这一点?我不知道我能做什么。

型:

public class RequisitionHeader
{
[Key]
public int RequisitionId { get; set; }
public string Applicant { get; set; }
public string Type { get; set; }
public DateTime? Date { get; set; }
public string ReasonOfChange { get; set; }
public DateTime? ValidityOfChangeFrom { get; set; }
public string Notes { get; set; }
}

接下来我会使用:

<label>@Html.RadioButtonFor(model => model.Type,"Material Master") Material Master</label>
<label>@Html.RadioButtonFor(model => model.Type,"Packaging Master") Packaging Master</label>
<label>@Html.RadioButtonFor(model => model.Type,"Other") Other</label>

或者编写自己的 mvc html 助手

最新更新