• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

mvc 3 partial vs ascx

I am working on converting web form to mvc 3
one of the issues I have is ascx. Currently, our web form web app has a folder contain all ascx

It is okay for me to re-write those, but I would like to learn the best approach.

if request.querystring("type") = "life insurance"
  show lifeinsurance.ascx
else if request.querystring('type") = "auto insurance"
  show autoinsurance.ascx
 show somethingelse.ascx

1. In mvc 3 world. what can I do?
2. Assume each ascx has different html control. How can I collect the value?
  • 2
1 Solution
Carl TawnSystems and Integration DeveloperCommented:
You can output a partial view based on it's name. So you could try adding the querystring value into the PropertyBag for the view, or as part of your model, and having it drawn dynamically from that:
@{ Html.RenderPartial(PropertyBag.Type); }

Open in new window

solution1368Author Commented:
can you show me the codes based on my situation? I just need to know how it works...
Carl TawnSystems and Integration DeveloperCommented:
Very simply, you'd be looking at something along the lines of:
// Controller action
public ActionResult Index()
    ViewData["Mode"] = "LifeInsurance";       // default

    // set partial view name from querystring
    if (Request.QueryString["type"] != null)
        ViewData["Mode"] = Request.QueryString["type"];

    return View();

Open in new window

Then in your view:

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now