views:

184

answers:

1

i am migrating a website from asp.net to asp.net mvc

in the asp.net site there are many places where they have "literal" tags and the server generates a bunch of html and sticks in in the literal tag.

what is the equivalent of doign this in asp.net mvc. Should i shove this in ViewData?

+4  A: 

The equivalent is to not make the same bad design choices the original developer made.

But, since we live in the real world, you'd shove their strings-which-contain-html into the presentation model for a particular page and then write it to the response stream.

In your Model:

public class MyPageModel
{
  public string HolyCrapItsHtml {get;set;}
}

In your controller:

public ActionResult MyPage()
{
  return View(new MyPageModel
         {HolyCrapItsHtml = OldCode.GetHtmlICantBelieveIt()});
}

And in your page:

<div>
  In the olden days, we'd concatenate our webpages together from strings like:
  <%= Model.HolyCrapItsHtml %>
</div>
Will
thanks for this response. can you offer an alternative approach that i can aim to refactor this to?
ooo
Essentially the same thing, except instead of concatenating your html together in (with this example) OldCode.GethtmlICantBelieveIt, in your controller you gather your data that makes up that html's content, place it within models, and render all your html within your view using your model's contents. A few minutes researching MVC and you'll get the hang of it.
Will