Questions tagged [html-helper]

Refers to the `HtmlHelper` class for ASP.NET MVC views.

HtmlHelper is a helper class specific to ASP.NET MVC. The platform includes extension methods for this class that can be used to render HTML markup given the model and other inputs.

The canonical example is the DisplayFor method, which renders a display for a given model property. In Razor syntax, it looks like this, which renders the value of SomeProperty belonging to the current model class:

@Html.DisplayFor(model => model.SomeProperty)

The volume of methods available in HTML Helper is extensive, and they make use of data annotations (for string formatting and client-side validation). Their usefulness makes them a core part of the ASP.NET MVC framework.

2251 questions
264
votes
10 answers

HTML.ActionLink method

Let's say I have a class public class ItemController:Controller { public ActionResult Login(int id) { return View("Hi", id); } } On a page that is not located at the Item folder, where ItemController resides, I want to create a…
Graviton
  • 81,782
  • 146
  • 424
  • 602
215
votes
13 answers

How to set a default value with Html.TextBoxFor?

Simple question, if you use the Html Helper from ASP.NET MVC Framework 1 it is easy to set a default value on a textbox because there is an overload Html.TextBox(string name, object value). When I tried using the Html.TextBoxFor method, my first…
dcompiled
  • 4,762
  • 6
  • 33
  • 36
189
votes
2 answers

How can I add a class attribute to an HTML element generated by MVC's HTML Helpers?

ASP.NET MVC can generate HTML elements using HTML Helpers, for example @Html.ActionLink(), @Html.BeginForm() and so on. I know I can specify form attributes by creating an anonymous object and pass that object for the (fourth in this case)…
Adrian Grigore
  • 33,034
  • 36
  • 130
  • 210
170
votes
3 answers
168
votes
8 answers

Razor HtmlHelper Extensions (or other namespaces for views) Not Found

I don't know if this was happening in the PR or Beta, but if I create an extension method on HtmlHelper, it is not recognized in a Razor powered page: namespace SomeNamespace.Extensions { public static class HtmlExtensions { public…
swilliams
  • 48,060
  • 27
  • 100
  • 130
135
votes
8 answers

Html helper for

Is there a HTMLHelper for file upload? Specifically, I am looking for a replace of using ASP.NET MVC HTMLHelper. Or, If I use using (Html.BeginForm()) What is the HTML control for the file upload?
Graviton
  • 81,782
  • 146
  • 424
  • 602
131
votes
7 answers

How to create a readonly textbox in ASP.NET MVC3 Razor

How do I create a readonly textbox in ASP.NET MVC3 with the Razor view engine? Is there an HTMLHelper method available to do that? Something like the following? @Html.ReadOnlyTextBoxFor(m => m.userCode)
Shyju
  • 214,206
  • 104
  • 411
  • 497
122
votes
4 answers

What's the difference between RouteLink and ActionLink in ASP.NET MVC?

I think that the title pretty much sums it up: What's the difference between RouteLink() and ActionLink() in ASP.NET MVC? i.e. when do you use Html.RouteLink() and when do you use Html.ActionLink() in your View?
Guy
  • 65,082
  • 97
  • 254
  • 325
118
votes
1 answer

How do you tell Resharper that a method parameter is a string containing a CSS class?

[Enable intellisense on HTMLHelper attribute for css classes] I have this HTMLhelper: public IHtmlString MyTextBoxFor( this HtmlHelper html, Expression> propertyExpression, string…
Raif Atef
  • 2,878
  • 1
  • 25
  • 31
113
votes
11 answers

ASP.NET MVC 3: Override "name" attribute with TextBoxFor

Is it possible when using Html.TextBoxFor to override the name attribute? I have tried with no success. I need to use TextBoxFor to get client side validation to work, however for reasons I won't go into I need the name of the textbox to be…
Rob Stevenson-Leggett
  • 35,279
  • 21
  • 87
  • 141
113
votes
7 answers

How do I apply a CSS class to Html.ActionLink in ASP.NET MVC?

I'm building an ASP.NET MVC application, using VB.NET and I'm trying to apply a css class to a Html.ActionLink using the code: <%=Html.ActionLink("Home", "Index", "Home", new {@class = "tab" })%> But when I run the code I receive the below…
LiamGu
  • 5,317
  • 12
  • 49
  • 68
110
votes
4 answers

What does Html.HiddenFor do?

Although I have read the documentation on Html.HiddenFor, I've not grasped what is it used for... Could somebody explain its uses and give a short example? Where should those helpers go in the code?
JPCF
  • 2,232
  • 5
  • 28
  • 50
90
votes
5 answers

How to change the display name for LabelFor in razor in mvc3?

In razor engine I have used LabelFor helper method to display the name But the display name is seems to be not good to display. so i need to change my display name how to do it.... @Html.LabelFor(model => model.SomekingStatus, new { @class =…
Sham
  • 1,191
  • 2
  • 13
  • 25
89
votes
3 answers

Adding CSS class to Html.BeginForm()

How to add class attribute for following situation (Using ReturnUrl only): @using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl })) { } I want something like this: @using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl }, new { @class =…
Vishal
  • 1,262
  • 1
  • 12
  • 19
85
votes
12 answers

Set disable attribute based on a condition for Html.TextBoxFor

I want to set disable attribute based on a condition for Html.TextBoxFor in asp.net MVC like below @Html.TextBoxFor(model => model.ExpireDate, new { style = "width: 70px;", maxlength = "10", id = "expire-date" disabled = (Model.ExpireDate == null ?…
Ghooti Farangi
  • 19,926
  • 15
  • 46
  • 61
1
2 3
99 100