ASP.NET MVC: Am I Doing It Right?

So, I'm an old web developer and new to MVC (not just ASP.NET in general). My views are starting to strongly resemble the good old classic ASP. Not that I add any business logic or anything else, but more presentation logic. I get a lot of tags <% %>

and operators if/else

to select which display links or styles to use.

I also thought about defining styles or references in the controller and setting them on the model, but sounds like a violation of MVC's purpose.

I end up ignoring <% %>

it to make sure my HTML is well formed.

I want to hear your opinion. Are your views the same as mine? Am I doing something wrong?

+2


source to share


4 answers


If I have a ton of presentation logic I am trying to move it to an extension from the HtmlHelper class.



+2


source


Along with what mxmissle said (I voted for it), I'll do a partial view of moving complex areas of the page into a separate file, this will help clean things up as well as code reuse.

I find that if things look too old school ASP, time to refactor. Surprisingly, you can scrape down to a helper class or partial view, or just repeat using something more succinct.



Edit: Also, if it's looking for a too old school ASP, maybe you have logic in your view that doesn't belong there.

+1


source


I usually create a ViewModel class for each view, containing any logic associated with a particular view. This is useful for situations where the conditional result is simply a simple DIV or SPAN tag that does not actually guarantee its own extension or partial representation.

I find it cleans up a lot of the classic ASP'ish look in my looks.

For more on this approach, see Stephen Walther's blog .

0


source


Yes, you are doing everything right. ASP.NET MVC is not an improvement over classic web forms in every way. This has its advantages and disadvantages ("soup-soup", as you discovered, is one of the disadvantages).

There are several ways to ease the pain (moving like logic into the model, HTML helpers, partial views, etc.), but it's hard to avoid.

0


source







All Articles