Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6835839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:16:50+00:00 2026-05-26T23:16:50+00:00

There are two ways of creating a custom HTML helper in ASP.NET MVC: You

  • 0

There are two ways of creating a custom HTML helper in ASP.NET MVC:

  1. You can create a class with a static method that outputs HTML, or
  2. You can add an extension method to the HtmlHelper class.

Option #1 seems simpler and easier.

  • What’s the advantage to Option #2?
  • When would I want to do that instead of Option #1?
  • Does Option #2 give you any sort of benefit or added features?

Edited to add :

In this particular situation, I’m trying to output a string that’s formed through a bunch of conditional logic. It seems wrong to put this in my model, but doing it all in Razor seems tedious and unnecessary — or am I wrong about that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:16:51+00:00Added an answer on May 26, 2026 at 11:16 pm

    On our current project we started by doing lots of HtmlHelper extensions but we realize that’s just the wrong thing to do, mostly because:

    • It breaks the pattern because you’re writing HTML through C# code, outside the Views.
    • It’s not validation friendly at all!!

    So we simply throw out almost all of those helpers and we’ve implemented ViewModels and Templates for all of the controllers. That’s the correct way of doing it.

    This is the best place to start: ASP.NET MVC 2 Templates, Part 1: Introduction

    Bottom line, if you’re building HTML through code, something is wrong with your project’s logic/pattern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have a std::list of some class. There are two ways you can
As far as I can tell, there are two main ways of creating functions
Is there any difference between following two ways of creating an object. Student s1
while creating a thread in java, there is two ways such as Extending threads
There are two ways to overload operators for a C++ class: Inside class class
I know of two ways of creating custom JSF components: 1. Native JSF way:
When using the Entity Framework there are basically two ways to create your model.
There are two ways of creating an object in javascript: use new on a
As far as I know there are two ways to create local variables in
I'm trying to create Excel 2007 Documents programmatically. Now, there are two ways I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.