html-helper

Styling Html Helpers MVC.Net

If i have a html helper like so: Name:<br /> <%=Html.TextBox("txtName",20) %><br /> How do i apply a css class to it? Do i have to wrap it in a span? Or do i need to somehow utilize the HtmlAttributes property of the helper? ...

Html.RenderPartial call from masterpage

Here is a scenario: Let's say I have site with two controllers responsible for displaying different type of content - Pages and Articles. I need to embed Partial View into my masterpage that will list pages and articles filtered with some criteria, and be displayed on each page. I cannot set Model on my masterpage (am I right?). How do I...

Better way to implement an Html Helper method?

I created an html helper Html.BreadCrumb(IDictionary<string, string> crumbs) Where the first string is the label and the second string is the URL. The helper creates the html required (an unordered list, some classes for first element, current element, last element, dead element and separators etc) All working nice, but I do this by ...

Testing HtmlHelpers in ASP.NET MVC

Is there any way to (unit) test my own HtmlHelpers? In case when I'd like to have custom control (rendered by HtmlHelper) and I know requierements for that control how could I write tests first - and then write code? Is there a specific (nice) way to do that? Is it worth? ...

Default modelbinding for enum in asp.net mvc?

I want a radio button generated with the Html.RadioButton() html helper to bind it's value to a field that has a struct as type. Less abstract: CommonProject.Services.SearchBag.Effects: public enum Effects { Any, Solid, Effect } In the strongly typed ViewData: public class SearchBag{ public Effects EffectIndicat...

Html.RadioButton sets all values to selected value

After tinkering around to solve [this][1] problem, I think the core of the problem is the following: When you use the Html.RadioButton() html helper with an Enum as value field, you can only choose your option once. AFter reposting the page, the helpers will ignore the value set in the call and set all radio buttons to the same value, b...

Sorting a List of Reviews Chronologically

I am trying to sort a list of movie reviews in chronological order. We have two options users can choose from, chronological and alphabetical. The page defaults to alphabetical, but when people click on the chronological option, nothing happens. Here is the code we have right now: // category 3 is 'reviews', category 12 is 'dvd reviews...

Do custom HTML Helper Classes violate the ASP.Net MVC model?

On a related post I mentioned that I have found custom HTML helpers to be just that, helpful, when developing. For instance, when I need paging for a "grid" I have a custom helper that I can call --> Html.Pager() Some have made a point that HTML helpers are a violation of the MVC model. Personally, I don't see it being any different t...

HTMl Helpers in MVC: How do I render html tags with helper such as ActionLink?

When using ActionLink to render data from database which has HTML tags (ie <p>) incorporated in it, ActionLink escapes the tags. What is the best way to handle this? ...

MVC helper extension

why do i get the error " Expected class, interface, enum or struct" with string underlined? public static string IsSelected(this HtmlHelper helper, string A, string B) { return "wtf"; } ...

List of HTML Helpers you use

I have found Html Helpers extremely useful to simplify view pages code. Apart from the ones included in the latest release of Asp.Net Mvc which one do you use? How much you can reuse them in different projects and are they linked only to html generation or did you put some custom logic inside? ...

Can I make ASP.NET MVC Html.RouteLink() return a url for my home page without an ID?

I've got a single route in my Global.asax.vb page like this... Shared Sub RegisterRoutes(ByVal routes As RouteCollection) routes.IgnoreRoute("{resource}.axd/{*pathInfo}") routes.MapRoute( _ "IdOnly", _ "{id}", _ New With {.controller = "Page", _ .action = "Details", _ ...

ASP.NET MVC: Using LINQ to XML to render (X)HTML

There has been a lot of discussions on View-engines for ASP.NET MVC and some criticisms against the inline "tag-soup" with for-loops and thing like it. The alternative or complement has been to use HTML-helpers, which are just inline method-calls. When I look inside ASP.NET MVC's HTML-helpers today they are using a class called TagBuil...

How to add static list of items in MVC Html.DropDownList()

I would like to assign a static list of items in a SelectList() to a Html.DropDownList() in ASP.NET MVC, what is the best practice? I was about to try to find a way to use new SelectList(new {key = "value"}... but one, that didn't work, and two, would I be breaking a law here, should my static list be declared in ViewData anyway and pas...

Why can't I specify a `name` attribute in an ASP.NET MVC form using Html.Helpers?

I am playing around with the ASP.NET MVC Html.Helpers and I noticed that say for instance: Html.Textbox("test"); will render the name attribute to "name=test" and the id tag will be "id=test" But when I do this: <%= Html.TextBox("go", null, new { @name = "test2", @id = "test2", @class = "test2" })%> id will be "id=test2" but name...

Are ASP.Net MVC HTML Helpers Overrated?

It is quite possible that I may not have got the point, but I really can't figure out how ASP.Net MVC's HTML Helpers can help me. Here's a sample: - HTML: <a href="ActionName" target="_blank">Click Me</a> HTML Helper: <%= Html.ActionLink("Click me", "ActionName", null, new {target="blank"}) %> My eyes are reading HTML more easily,...

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 error: Compiler Error Message: BC30988: Type or 'With' expected. I'm new to MVC and really hav...

view data dictionary overriding Model data in asp.net mvc

Hello gurus, I have a view to create a user as follows: <% using (Html.BeginForm("SaveUser", "Security")) {%> <p> <label for="UserName">UserName:</label> <%= Html.TextBox("UserName") %> <%= Html.ValidationMessage("UserName", "*") %> </p> <p> <label for="Passwor...

How to pass parameters to Controller-Action using LinkButton Click

Hi, I have a list view for one of my controller's index action. In that View's source, I have added the following code to the for loop present inside the source of View. <%= Html.ActionLink("Select", "ActionName", new object { controller = "Home", action = "ActionName", iID1 = Convert.ToInt32(ViewData["ID"].ToString()), iID2 = Convert....

HTML Helpers and Partial Views

If I have say a Partial View called MypartialView and I have a HTML Helper called "MyHTMLHelper" how can I return a partial view from the helper? My requirement is that sometimes I'd like to render a PartialView on it's own and other times I'd like to render it with another partial view, or a slab of text or something. So I thought I c...