0

I know there are a lot of utility and helper classes/methods for generating URLs and links from internal routes and controllers. But how would you tackle the below in MVC 3?

In a razor file someone has defined this:

<a href="http://@Model.Details.ExternalURL" target="_blank">Website</a>

ExternalURL in this instance will hold values like www.yoursite.com, without any prefixes. Hard-coding an http:// at the start is an obvious no-no but how best to handle this?

3
  • 2
    Why is hard-coding http bad? Commented Oct 5, 2012 at 22:51
  • 1
    I would make EternalULR a fully qualified url string. Then <a [email protected] target="_blank">Website</a> Commented Oct 5, 2012 at 22:55
  • @dbaseman-- maybe not bad, but I'd like to have some flexibility in case its an https connection needed. Forty-Two has a good idea, I'd say. Commented Oct 5, 2012 at 23:01

1 Answer 1

1

It's not so bad to hardcode http:// in your case, but if you want to avoid it, I see few options, but maybe most correct will be to extend your model with property @Model.Details.ExternalUrlLink or something like that. In getter you can do any logic what you want over original value, e.g. concatenate http:// prefix if it's not presented

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.