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
0
votes
2 answers

What is the equivalent of @Model.propertyname in ASP Tag Helpers?

In vanilla HTML Helpers, I usually use
@Model.Name
to print Name property, is there similar function for Tag Helpers?
tickwave
  • 3,335
  • 6
  • 41
  • 82
0
votes
1 answer

Select dropdown value after post

I was hoping for some guidance on an issue I am having with preserving the value in a dropdownlist after post (razor) I have a simple page: @model testContingency.Models.ListByWardDD @{ ViewBag.Title =…
0
votes
0 answers

Add HTML attribute to anonymous type without changing method signature

I have an HtmlHelper extension method that I am writing for an MVC/Razor website. The method signature is as follows: public static IHtmlString CharacterCountOf( this HtmlHelper htmlHelper, …
Thomas927
  • 853
  • 1
  • 11
  • 19
0
votes
2 answers

Validate HTML Textbox

I have this textbox: <%= Html.TextBox("EffectiveDate", Model.EffectiveDate.HasValue ? Model.EffectiveDate.Value.ToString("dd-MMM-yyyy") : "", new { @class = "economicTextBox", propertyName = "EffectiveDate", onchange = "parseAndSetDt(this); ",…
slandau
  • 23,528
  • 42
  • 122
  • 184
0
votes
1 answer

Custom HtmlHelper with same method signature as System.Web.Mvc version - Ambiguous Invocation

I have a slightly customized version of the LabelFor() Html Helper found in the MVC2 sources. When I use it in a view I get an "Ambiguous Invocation" error - which makes perfect sense given that my also retains the signature of the…
nerraga
  • 614
  • 7
  • 17
0
votes
0 answers

Change sorting method based on user dropdown selection

I am trying to allow user to choose a sort method from a dropdown list.I am not fully certain how to accomplish this. Here are my beginnings. RestaurantVm.cs: I am trying to allow user to choose a sort method from a dropdown list.I am not fully…
Curious-programmer
  • 772
  • 3
  • 13
  • 31
0
votes
0 answers

Populate form with model data after it has rendered ASP.NET

Context: Building a web app using ASP.NET MVC 5 with EF 6.1.3 linked to an SQL Server database. I have a pre-loaded form which I am trying to dynamically populate based on a drop down list (in this case it is car registrations). Ideally, upon…
MJ_Wales
  • 873
  • 2
  • 8
  • 20
0
votes
3 answers

Duplicate name attribute generated for the HTML Helper

I get a duplicate name attribute while validating through https://validator.w3.org @Html.EditorFor(model => model.User_Name, new { htmlAttributes = new { @class = "form-control", id = "txtFullNameRealtor", @Name = "txtFullNameRealtor", placeholder =…
Ayush
  • 11
  • 2
0
votes
1 answer

ASP.MVC Html helper to format text

My string is: string title = "CaSiO<sub>3</sub> perovskite in diamond indicates the recycling of oceanic crust into the lower mantle." I used @Html.Raw(title) and got CaSiO3 perovskite in diamond indicates the recycling of…
user2109581
  • 187
  • 2
  • 2
  • 11
0
votes
1 answer

MVC invoking default page when opening a different page?

I've got a simple MVC (RC1) app set up, and I'm seeing some odd behavior. The Home/Index page shows a list of items using a ListView. Here's the HomeController code: Function Index() ViewData("results") = From m In context.MyTable Return…
gfrizzle
  • 12,419
  • 19
  • 78
  • 104
0
votes
1 answer

Custom HTML helper : how do I get the value of the lambda expression?

I want to create a custom HTML helper (Image) that is used in views of a mvc5 app. It is going to be called with a lambda expression, just like the out-of-the-box helper EditorFor @Html.EditorFor(model => model.Name) @Html.Image(model =>…
kahoona
  • 175
  • 2
  • 14
0
votes
0 answers

MVC Html Helper DisplayName use

To my knowledge the html helper method DisplayNameFor will take the value set in Display attributed decorating the property in the expression passed to it, so for example for the following property. [Display(Name = "Name", ResourceType =…
Sisyphus
  • 900
  • 12
  • 32
0
votes
1 answer

Parameters to helpers

I did this custom helper: public static System.Web.Mvc.MvcHtmlString RzTextBoxForCNPJ(this System.Web.Mvc.HtmlHelper html, System.Linq.Expressions.Expression> expression) { …
Neumann
  • 319
  • 2
  • 14
0
votes
0 answers

Extract HTML Helpers from Razor views

Situation We are rebuilding a web application (winforms), from the ground up. The old application will keep running, when the new one is released. This means that the new application needs to talk to an old database, I can't change anything there.…
0
votes
2 answers

How to Render( ) instead of ToString()

I'm trying to compile my own set of controls in MVC3. So, rather than create HTML Helper extensions for all of them, I figured I would mimic the behavior of other frameworks (Telerik, DevExpress). So I created a new helper extension to offer up my…
tbddeveloper
  • 2,407
  • 1
  • 23
  • 39
1 2 3
99
100