我们可以在asp.net mvc中使用html标签吗?

时间:2016-03-10 07:01:18

标签: html asp.net-mvc html5 asp.net-mvc-3 asp.net-mvc-4

我想在asp.net mvc中使用以下html标签,是否可能?

<form action="demo_form.asp">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit" value="Submit">
</form>

2 个答案:

答案 0 :(得分:-1)

您只需使用这些代码将您的视图视为强类型视图即可使用此代码。我希望这会对您有所帮助。

C#控制器代码

 public ActionResult Index()
    {
        return View();
    }
    [HttpPost]
    public ActionResult Index(sample b)
    {
        return View();
    }

C#类代码

 public class sample
{
    public string fname { get; set; }
    public string lname { get; set; }
}

Razor查看代码

    @model WebApplication1.Models.sample

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>


    @using (Html.BeginForm("index","Home"))
    {
          <input type="text" name="fname"><br>
  <input type="text" name="lname"><br>
  <input type="submit" value="Submit">
    }

</body>
</html>

enter image description here

答案 1 :(得分:-1)

如果您不想创建强类型视图,那么您可以这样做。

[HttpPost]
    public ActionResult Index(string fname, string lname)
    {
        return View();
    }
相关问题