htmlhelpers

ASP.NET MVC: 'Extend' Html.TextBox to conditionally have CSS value?

Hello, I would like to extend ASP.NET MVC's TextBox so it conditionally switches its CSS value (based on data from the Model). However, I don't want to put that logic in my view (by conditionally changing htmlAttributes/via method call there), but instead extend the class so I don't clutter my view. Basically I want the TextBox on creati...

Using EditorFor<> to render a drop-down list

So far we can use Html.EditorFor() to dynamically render the appropriate template for a datatype - e.g. string, int, or a custom type, say 'Address'. Now I want to use EditorFor() to render a 'Parent' field. I want a drop-down containing every row, and the user picks a parent from this drop-down. The 'Parent' template has access to the...

Persisting Selected Value in MVC DropDownLists

I'm new to MVC, but I've been all over this, read all the documentation and all the questions and all the blog posts I can find, and all I'm doing is getting completely wrapped around the axle. I'm trying to make a "create" Action and View. My data entry is relatively straight forward, and common: I have a drop down list and a text box....

Override EditorForModel Template

Hi, You can provide alternate templates for individual types, but is it possible to override the template that wraps the label, field and validation up. Change: <div class="editor-label"><label for="Content">Content</label></div> <div class="editor-field"><input class="text-box single-line" id="Content" name="Content" type="text" valu...

Unit Testing HtmlHelper that Needs to Access Data Layer

I am trying to create a unit test for an HtmlHelper that accesses my data layer to get a string. I have looked at a lot of posts around this and I am probably missing something. The problem that I am having is how do I mock the access to my data layer? I usually do my dependency ijection through the constructor, but I cannot here beca...

Why is there no Html.CheckBoxFor() method in .Net MVC?

The latest MVC release contains some type safe html helper extension methods, for example, CheckBoxFor() and LabelFor() does anyone know if there is a particular reason why they haven't implemented a CheckBoxFor()? ...

How to create MVC HtmlHelper table from list of objects

I am trying to create a specific HtmlHelper table extension to reduce the spaghetti code in my View. Taking a list of domain objects I would like to display a table that is a little bit more intelligent in using the properties of the domain object as columns. In addition, I would like to disable showing of some properties as columns. An...

Using ASP.NET MVC Html Helpers in a standard web forms project

So for example in the code behind of a web form aspx page I would like to be able to do things like string textBoxHtml = Html.TextBox("MyTextBox"); Is this possible? Is the source code available to fork for webforms? ...

Need help coming up with a better HtmlHelper Extension method.

Hi all, I've inherited the following code and i was wondering if i could pick at your brains to see if there's a nicer way to do duplicate this. Heres the html for most of our partial input views <% if (Html.IsInputReadOnly()) { %> <td> Id </td> <td> <%= Html.TextBox( "Id" , (Model == null ? null : Model.Id) , new { @read...

How To Call The RenderAction in my Html Helper?

im extending the htmlhelper. but it i cannot call the renderaction of it. using System.Text; using System.Web.Mvc; using System.Web.Mvc.Html; public static class ViewHelpers { public static string Text(this HtmlHelper htmlHelper, string name, object value, bool isEditMode) { htmlHelper.RenderAction(......

Using strongly-typed HTML helpers with composite Views

I have a a simple registration DTO with several sting properties: Username, Password, Email To the view I pass in a strongly-typed ViewModel, that itself has the registrationDTO but also has additional properties to display in the view. When using strongly typed html helpers, on the registrationDTO properties, I need to say Html.Editor...

Foreach on IEnumerable property and CheckBoxFor in ASP.Net MVC

I believe this question applies to any of the "For" Html helpers, but my specific problem is using CheckBoxFor... I have a model that is of type IEnumerable, where rights is a simple POCO. This model is actually a property of a bigger model that I created an EditorTemplate for. Here is the bigger picture of my model: public class big...

How does one add an "id" attribute to Html.LabelFor() in ASP.NET MVC2?

How would one add an "id" attribute to Html.LabelFor() in ASP.NET MVC2? This is my label code: <%=Html.LabelFor(x => x.FirstName)%> This is my failed attempt: <%=Html.LabelFor(x => x.FirstName, new { @id = "first-name" } )%> Thanks. ...

Uniquely Naming fields in MVC using html helpers

if i have created a view model and have a partial form that is a create form for the view model. but now i want to take in a list model to my form and be able to loop through each item and depending on one of the properties append a string to teh end of the Name and id fields. or alternatively give each of the items in the list a unique ...

ASP.NET MVC2 - Does Html.EditorForModel() work on the nested data model?

My test shows it doesn't work. It ignores the nested data in model. Can anyone confirm this? ...

Custom Html Helper is not working in asp.net MVC 2.0

Hey I was using this custom html helper in asp.net mvc 1.0 but now I am trying to use it in a 2.0 project and it crashes http://blog.pagedesigners.co.nz/archive/2009/07/15/asp.net-mvc-ndash-validation-summary-with-2-forms-amp-1.aspx This is the error I get. System.MissingMethodException was unhandled by user code Message=Method not...

ASPNET MVC 2 LabelFor prefix overload

I refer to this question. The answer offered works really well but it doesn't seem to take the data annotation attributes for the DisplayNameAttribute into account when using the new labelfor helper. This is the code I am using: public static MvcHtmlString LabelFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, string prefix,...

ASP.NET MVC: View does not get rendered with updated model value

I'm experiencing the a challenge in populating the child records. My previous code was like - <%= Html.TextBox("DyeOrder.Summary[" + i + "].Ratio", Model.DyeOrder.Summary[i].Ratio.ToString("#0.00"), ratioProperties) %> This code does not render the updated values after post back. To resolve this issue my work around was like - <%=...

HtmlHelper using ViewContext.Writer not rendering correctly

Hi, I am building a simple CMS with asp.net MVC and I have almost all the parts working. I have one minor issue which I can't work out how to solve. I have a Html helper method that renders the content of area. This method however uses the Response.Write to write its content rather than returning a string. The reason for this is that I'...

HTMLHelper RadioButton

Hello I'm new in .net Family and i've been looking asp.net webpage and following the MVC tutorials the problem is I'm using LinQ to Sql (2005) model and C# and i need to put a radioButton to know if a date must be initialized or not how do i do this using html helpers ?? ...