【问题标题】:can we use html tags in asp.net mvc我们可以在asp.net mvc中使用html标签吗
【发布时间】:2016-06-24 21:30:22
【问题描述】:

我想在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>

【问题讨论】:

  • 你为什么不试试呢!

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


【解决方案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>

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-21
      • 1970-01-01
      相关资源
      最近更新 更多