材料设计中的单选按钮/复选框

时间:2018-06-20 11:31:27

标签: asp.net-mvc model-view-controller material-design

我在mvc中使用材质设计。在mvc中添加单选按钮/复选框时,我使用此代码。

@Html.RadioButtonFor(e => e.Type, 0, new { id = "hair-short1", @class="with-gap" })
@Html.Label("hair-short1", "Short")
@Html.RadioButtonFor(e => e.Type, 1, new { id = "hair-short", @class = "with-gap" })
@Html.Label("hair-short", "Short")

可以,但是当单击提交按钮类型为空时。

对于复选框,我使用此代码

 <input id="Diabetes" class="chk-col-red" checked="" type="checkbox">
 <label for="Diabetes">دیابت</label>

和在视图模型中

 public ActionResult Add()
  {
   ViewBag.Action = "Add";
   return View(new Referred());
  }

 [HttpPost]
 public ActionResult Add([Bind(Exclude = "Id,CreatedDateTime,CreatedUserId")]Referred model)
  {
   if (ModelState.IsValid)
    {
      model.CreatedDateTime = DateTime.Now;
      model.CreatedUserId = WebSecurity.CurrentUserId;
      _db.Referreds.Add(model);
      _db.SaveChanges();
      return RedirectToAction("Index");
     }
     else
     {
     ViewBag.Action = "Add";
     Warning("لطفا صحت اطلاعات ورودی را بررسی کنید.", dismissable: true);
     return View(model);
       }
    }

和型号

  [Required(ErrorMessage = "*")]
  public bool? Type{ get; set; }

1 个答案:

答案 0 :(得分:0)

您必须使用单选按钮的输入类型进行材料设计。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>be.jschoreels.camel</groupId>
    <artifactId>camel-simple</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.19.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms</artifactId>
            <version>2.19.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jetty</artifactId>
            <version>2.19.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-camel</artifactId>
            <version>5.15.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-all</artifactId>
            <version>5.15.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.activemq/activemq-kahadb-store -->
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-kahadb-store</artifactId>
            <version>5.15.3</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.25</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.25</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
    </dependencies>


</project>