将以下内容复制到cshtml文件中

@using Microsoft.AspNetCore.Html
@{
    ViewData["Title"] = "";
}

<p>AntiForgeryToken的使用</p>
@Html.AntiForgeryToken()
<p>ActionLink的使用</p>
<br />
@Html.ActionLink("LinkText", "RazorShow")


@Html.ActionLink("带控制器", "ActionName", "ControllerName")


@Html.ActionLink("带路由信息", "ActionName", new { id = 1, name = 3, age = 4, height = 5 })


<a href="/Html/ActionName/1?name=3&age=4&height=5">带路由信息</a>


@Html.ActionLink("链接", "action", new { id = 1, name = 3, age = 4, height = 5 }, new { @class = "classText", style = "width:200px", tt = "xxx" })


<a class="classText" href="/Home/Index/@DateTime.Now" style="width:200px" tt="xxx">Home</a>
<p>RouteLink的使用</p>


@Html.RouteLink("LinkText", new { action = "ActionName" })

@Html.RouteLink("LinkText", new { action = "ActionName", controller = "ControllerName" })

@Html.RouteLink("LinkText", new { action = "ActionName", id = 1 })



<p>Input 输入框的使用-TextBox</p>
@Html.TextBox("NameId")


@Html.TextBox("NameId", "Value")


@Html.TextBox("NameId", "Value", new { @class = "classText", @style = "width:200px", @tt = "xxx" })

<p>Input 输入框的使用-Hidden</p>
@Html.Hidden("NameId")


@Html.Hidden("NameId", "Value")

<br />
<p>Input 输入框的使用-Password</p>
@Html.Password("NameId")


@Html.Password("NameId", "Value")

<p>Input 输入框的使用-CheckBox</p>
@Html.CheckBox("NameId", true)


@Html.CheckBox("NameId", false)
<p>Input 输入框的使用-RadioButton</p>

@Html.RadioButton("NameId", "Value", true)


@Html.RadioButton("NameId", "Value", false)



<p>Input 输入框的使用-DropDownList,ListBox</p>
@{
    SelectListItem item;
    List<SelectListItem> list = new List<SelectListItem>();
    for (int i = 1; i < 5; i++)
    {
        item = new SelectListItem();
        item.Text = "Text" + i;
        item.Value = "Value" + i;
        item.Selected = (i == 2);
        list.Add(item);
    }
}

@Html.DropDownList("NameId", list)


@Html.ListBox("NameId", list)

<p>表单的Get提交</p>
@using (Html.BeginForm("PostData", "Html", FormMethod.Get))
{
    ;
    @Html.TextBox("UserNameGet")
    ;
    @Html.Password("PasswordGet")
    ;
    <input type="submit" value="SubmitButton" />
}



<p>表单的Post提交</p>
@{
    Html.BeginForm("PostData", "Html", FormMethod.Post);
}

@Html.TextBox("UserNamePost")

@Html.Password("PasswordPost")

<input type="submit" value="SubmitButton" />
@{
    Html.EndForm();
}
View Code

相关文章: