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 4572050
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:35:28+00:00 2026-05-21T19:35:28+00:00

I have created a Model class lets say Products. I want to have a

  • 0

I have created a Model class lets say Products. I want to have a property ‘ItemName’ return an HTML link everytime it is put into an HTML document. For example:

public class Product
{
    int ItemID {get; private set;}
    [HtmlReturn(Link=Html.ActionLink("Products", "Details", new {id=ItemID})] // <-- Something like this
    int ItemName {get; private set;}
    int Price {get; private set;}
}

Now anytime the ItemName is used in an HTML document, the value is output as a link to the Product/Details page for that item. This would allow output of the ItemName in many different locations with the assurance that it will always be a link anywhere it is referenced on a web site.

  • 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-21T19:35:29+00:00Added an answer on May 21, 2026 at 7:35 pm

    You could implement a separate member variable with a get-only accessor in your Product class called ItemAsLink, that returns the HTML formatted link value. That is what I usually do when running into a situation like this. It has the disadvantage of moving some of the UI/view/display code into the model, but as you say, it helps with code reuse.

    The way you are suggesting does the same thing (moves code that should be in the view into the model). In my opinion, it also would be confusing, because ItemName would have a different value depending on how it was called. That violates the expectation that ItemName is always the same regardless of how it is used.

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

Sidebar

Related Questions

so lets say I have a simple class Final and I want to filter
Let's say I have: class Like(db.Model): user = db.ReferenceProperty(User,collection_name='likes') photo = db.ReferenceProperty(Photo,collection_name='likes_received') created =
I have a model with a datetime field: class MyModel(models.Model): created = models.DateTimeField(auto_now =
Lets say I've got an object model, where I have many collections of the
Let's say I have a model that looks like this: public class Blog {
Let's say I have a set of Django Models: class Article(models.Model): title = models.CharField(max_length=100,
I have a simple 1:many aggregate relationship, lets say: public class Parent { public
Let's say in my model I have public DateTime Date {get;set;} property. On the
Let's say I have a model like this (simplified from the original): public class
Let's say you have a SiteUpdate and a Comment model, and you want to

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.