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

时间:2022-12-02 10:13:21

I want to use following html tags in asp.net mvc,is it possible?

我想在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 个解决方案

#1


-1  

You just have to make your view as strong typed view using these code u get able to use this code.I hope this will help u.

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

C# Controller Code

C#控制器代码

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

C# Class Code

C#类代码

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

Razor View Code

剃刀查看代码

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

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

#2


-1  

If you do not want to create a Strongly Typed View then you can just do like this.

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

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

#1


-1  

You just have to make your view as strong typed view using these code u get able to use this code.I hope this will help u.

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

C# Controller Code

C#控制器代码

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

C# Class Code

C#类代码

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

Razor View Code

剃刀查看代码

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

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

#2


-1  

If you do not want to create a Strongly Typed View then you can just do like this.

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

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