.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Html Helpers and Exceptions

Posted By:      Posted Date: August 23, 2010    Points: 0   Category :ASP.Net


I have been working in a few MVC HTML Helpers. For example:

    public static MvcHtmlString GoogleAnalytics(this HtmlHelper helper, String account, String url) {
      // ...

If account or url are null should I trhow an exception? Or render an empty string? Or render an Html comment in the view?

What is the recommended approach for this?



View Complete Post

More Related Resource Links

System.EntryPointNotFoundException: Entry point was not found. when unit testing html helpers


I'm trying to unit test a very simple html helper but keep getting the following exception:

System.EntryPointNotFoundException: Entry point was not found.

public static string AdditionalUsersDropDownList( this HtmlHelper helper, int additionalUsers )


Dictionary<int, string> items = new Dictionary<int, string>( );

items.Add( 0, "None" );

for ( int i = 1; i <= 30; i++ )


items.Add( i, i.ToString( ) );


SelectList list =  new SelectList( items, "Key", "Value", additionalUsers );

return helper.DropDownList( "AdditionalUsers", list );


stupid -- why does model.Model break Html helpers?



This code in an aspx file:

      <%: Html.TextBoxFor(model => model.Model) %>

Breaks the page with the following error - which I think is stupid as Model is a property of my Product Entity and relates to the Model of the product (e.g. Make, Model, Year). If I remove this model.Model reference the rest of the Product properties render as expected. I am stuck with renaming my property?

Value cannot be null or empty.
Parameter name: name

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Argu

Creating HTML Helpers with Extension Methods


namespace MvcLogin_Validation.Helpers
    public static class LabelExtensions
        public static string Label(this HtmlHelper helper, string target, string text)
            return String.Format("<label for='{0}'>{1}</label>", target, text);



Above is my html helper class.

<%= Html.Label("first name", "First name") %>

This is how I use it.

Now while using it I am getting an error which says, "  No overload for method 'Label' takes '2' arguments ", where as this link ( http://www.asp.net/mvc/tutorials/creating-custom-html-helpers-cs) says to do it exactly as i did.

Can anyone please guide where I am going wrong.



Can we use Html Helpers/Repositary Pattern/Ninject in Webforms?


Just Wondering. Can we use Html Helpers/Repositary Pattern/Ninject in Webforms?


how can we use Strongly Typed Html Helpers in webmatrix?


I know we can use the HTML helpers, but how about the strongly typed one's?


How to use html helpers in WebGrid


Hi all,

How can use html helpers in WebGrid Columns.

I tried like this. but there was error like the best overloads method parameter

    ViewBag.Title = "News";
    Layout = "~/Views/Shared/_Layout.cshtml";
@model IQueryable<Connect.Models.News>
    News Listing</h2>
    var grid = new WebGrid(Model);
    grid.GetHtml(columns: grid.Columns(
        grid.Column("ID", "ID"),
        grid.Column("Name", "Name", format: @<b>@item.Name</b>),
        grid.Column("Seourl", "Given Seourl"),
        grid.Column( header: "English", format: Html.RouteLink("Entry", new{ })  ),

I'm referring to

        grid.Column( header: "English", format: Html.RouteLink("Entry", new{ })  ),

THanks a lot!

Why ID are rendered capitalized ID by all Html helpers.


All html helpers, like Html.EditorFor(x => x.UserName) render an attribute ID capitalized

Is there a way to have the opposite

Thank you


What are HTML Helpers in ASP.NET MVC?
What Standard HTML Helpers renders?

ASP.NET, HTML, JavaScript Snippet Support (VS 2010 and .NET 4.0 Series)

This post covers another useful improvement in VS 2010 - HTML/ASP.NET/JavaScript snippet support. Snippets allow you to be more productive within source view by allowing you to create chunks of code and markup that you can quickly apply and use in your application with a minimum of character typing.

Visual Studio has supported the concept of "snippets" for VB and C# in previous releases - but not for HTML, ASP.NET markup and JavaScript. With VS 2010 we now support snippets for these content types as well.

Maintain HTML Radio Button Selection Inside GridView After Postback

Long time ago I wrote an article about getting the value of the selected RadioButtons inside the GridView control. The code did not addresssed the postback issue which means that the selected radio button was cleared after the postback occurs.

How to get more information about the exceptions that can happen in SharePoint 2010 projects?

In case there is an exception anywhere in the SharePoint 2010 project (most common place an exception would happen is during deployment of your SharePoint project, custom deployment configuration or custom deployment steps), there's a registry key EnableDiagnostics available for you to use.

Rendering ASP.NET Script References into the Html Header

One thing that I've come to appreciate in control development in ASP.NET that use JavaScript is the ability to have more control over script and script include placement than ASP.NET provides natively. Specifically in ASP.NET you can use either the ClientScriptManager or ScriptManager to embed scripts and script references into pages via code.

Getting value of Html.TextBoxFor(m => m.name)


Hi All,

I am new to Asp.net MVC 2. I am unable to get value for Html.TextBoxFor(m = > m.name) in view. I can get this value in Controller.

How to get this value in view.

Please help.

Embed Youtube inside Ajax Html Editor- problem



When inserting a simple embed of youtube inside the ajax editor, on firefox and chrome problems occur. On the other hand on internet explorer 8 everything works fine. I found this solution http://www.nopcommerce.com/boards/t/4228/bug-in-ajax-html-editor.aspx . 

My question is where do I find the DesignPanel.pre.js ?


Roderick Vella

Re-positioning an HTML container with javascript onresize with a Master page.


I have an HTML <div> container that I float to the right of a gridview.  When the browser window is maximized, it looks fine.  When minimized, the gridview positions below the floating container and most of the data is pushed off the bottom of the browser - you have to scroll down to see it.

If I position the floating container above the gridview it looks fine in a minimized window, but looks real bad when maximized.

What I want to do is use a javascript: onresize event to re-position the floating container up or down depending on the window.inner.width AND do it with a Master/Content page structure AND do it for only the one page where needed.

I can capture the onresize event and display the window dimensions but haven't figured-out how to do it with a Content page that still uses the Master page.  I think I'm having a very "thick" week...

- Tinker


adding a url to html img


I am having an html img tag in which the user is being shown images. However I now want to open a url when the user clicks my img. 
What do I need to do to be able to achieve this? 

VS 2010 HTML validation "in CSS" option - where the hell is it?


In VS 2008 there is a very useful feature of background HTML validation - it checks if CSS class name is valid i.e. it exists in one of the linked css files. But VS 2010 Express does not do that any more. And the relevant setting in Options->Text Editor->HTML->Validation->in CSS is not there. Ok, maybe they made it paid for option? VS 2010 Professional? Not there. Or maybe VS 2010 Ultimate? Not a trace.

1. am I blind?

2. they decided it is too convenient to use and removed it?

3. they will "introduce" it in SP1?

What is going on? That one thing made me move back to VS 2008 web developer.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend