【问题标题】:ASP.NET MVC combining radio buttons with text boxASP.NET MVC 将单选按钮与文本框相结合
【发布时间】:2018-08-16 22:11:00
【问题描述】:

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

我尝试了一些东西,但它只从第三个单选按钮存储到 DB 值,而不是从文本框中。

      @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; }
}

【问题讨论】:

  • 你的模特是什么样子的?
  • 我添加了模型。你可以看看
  • 我会将 model.type 从“其他”的单选按钮移动到用户键入“其他”的文本框中。

标签: c# asp.net-mvc razor


【解决方案1】:

我会使用下一个:

<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 helper

【讨论】:

    猜你喜欢
    • 2011-01-13
    • 1970-01-01
    • 2014-10-11
    • 1970-01-01
    • 2011-09-09
    • 2018-12-07
    • 2012-01-23
    相关资源
    最近更新 更多