如何在ASP.NET MVC的HTML中创建按钮?

Aid*_*inn 9 html c# asp.net asp.net-mvc razor

我正在为索引页面制作一个小表单.

@model MarketPlace.Models.Download
@{
    ViewBag.Title = "Index";
}
@using (Html.BeginForm("Index", "Downloads", System.Web.Mvc.FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <td>@Html.DisplayNameFor(model => model.EMail)</td>
    <td>@Html.TextBoxFor(model => model.EMail, new { @class = "form-control round-input", @style = "width:200px" })</td>
    <td>@Html.DisplayNameFor(model => model.Reference)</td>
    <td>@Html.TextBoxFor(model => model.Reference, new {@class = "form-control round-input", @style = "width:200px"})</td>
    <td>@Html.DisplayNameFor(model => model.Products)</td>
    <td>@Html.Buttonorsomething
}
Run Code Online (Sandbox Code Playgroud)

我以为会有一个`@Html.Button或其他东西,我在Google上搜索,但显然他们没有添加一个.

我的问题是,我该如何制作一个按钮?

编辑:请注意,我一直在使用ASP.NET MVC很短的时间,请原谅我这个愚蠢的问题!

Aru*_*K V 14

只需包含纯HTML按钮就可以了

喜欢

<input type="button" value="Create" /> 
Run Code Online (Sandbox Code Playgroud)

如果你想要一个HTML按钮,那么它将调用你的MVC控制器的动作方法.试试这个

<input type="button" value="Create" onclick="location.href='@Url.Action("Create", "User")'" />
Run Code Online (Sandbox Code Playgroud)

  • 不要使用干扰性的 JavaScript。 (2认同)

Cod*_*ter 5

您可以在Razor中使用HTML:

<input type="submit" />
<input type="button" />
Run Code Online (Sandbox Code Playgroud)

没有每个HTML元素都有一个帮助器。