0

I have some mvc3 code that I'm taking ownership and there are views that both apply html helpers and html javascript injection within views.

Personally, I prefer raw html or helpers as opposed to html injection. What are the pro's and cons of each?

Basic html and helpers:

        <div id="efI" class="ef">
            @Html.PasswordFor(m => m.Password)
            @Html.ValidationMessageFor(m => m.Password)
        </div>
        <div>
           @Html.ActionLink("Click here.", "SomeAction")
        </div>

Injection::

    @Html.EditorForModel()  //this generates controls from above...
    <script type="text/javascript">
       $('#efI').append('<div>@Html.ActionLink("Click here.", "SomeAction")</div>');
    </script>

2 Answers 2

2

Not really much difference in the static example you provide. Usually injections are made with dynamically created HTML (for example,table cells managed by AJAX calls to a DB).

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

4 Comments

But why would you ever use injection to insert static content, like in this example?
For static content, you got me...Maybe as a learning exercise. I don't see any point in doing it versus just the basics. It is just static content after all.
@primatology: Hi, I updated the contents page...in this case the only thing that I have to work with possibly is an existing @HtmlEditorFor() block (instead of static html content).
@TravisJ: Totally agree with your perspective!
1

It depends. Injection in my opinion is more expensive, it makes some javascript calls in your case. Injection maybe suitable when using templates of html (jquery.tmpl).

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.