Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you create a button in HTML for ASP.NET MVC? [duplicate]

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!

like image 419
Aidan Quinn Avatar asked Feb 05 '15 09:02

Aidan Quinn


2 Answers

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

like image 67
Arunprasanth K V Avatar answered Sep 28 '22 15:09

Arunprasanth K V


You can just use HTML in Razor:

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

There isn't an helper for every HTML element.

like image 25
CodeCaster Avatar answered Sep 28 '22 17:09

CodeCaster