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!

4

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Don't use obtrusive JavaScript.
6

You can just use HTML in Razor:

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

There isn't an helper for every HTML element.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.