13

Im making a small form for an index page.

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

I thought there would have been a `@Html.Button or something, and I searched on Google, but apparently they didn't add one.

My question is, how can I make a button?

edit: Please note, I've been using ASP.NET MVC for a very short time now, please forgive me for this silly question!

Aidan Quinn
  • 1,178
  • 4
  • 20
  • 33
  • simply include pure html button it will work – Arunprasanth K V Feb 05 '15 at 09:37
  • If you need helper - look here http://stackoverflow.com/questions/5955571/theres-no-html-button – fly_ua Feb 05 '15 at 09:38
  • Check this [SO post](http://stackoverflow.com/questions/5955571/theres-no-html-button). It has some discussion why there is no `@Html.Button` and how you can create custom html heler to render a `button`. – Michael Feb 05 '15 at 09:39
  • Best example from our own Microsoft (www.asp.net) Link: https://www.asp.net/mvc/overview/getting-started/introduction/adding-search – TheKingPinMirza Feb 02 '17 at 17:46

2 Answers2

18

simply include pure html button it will work

like

<input type="button" value="Create" /> 

if you want a HTML button that will call your MVC controler's action method then . try this

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

Note : The best practice is to avoid obtrusive Javascript, you can have it as a separate onclick method.

Update :

If you really want a helper then you can create a custom helper class type of MvcHtmlString

a good example you can find here

Arunprasanth K V
  • 20,733
  • 8
  • 41
  • 71
6

You can just use HTML in Razor:

<input type="submit" />
<input type="button" />

There isn't an helper for every HTML element.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272