[RESOLVED]Render particular controls on a page depending on what page is requested

Hello,

We are currently in the process of building an application, the user can choose from 5 different categories, depending on what they choose will determine what controls get rendered on the page i.e drop downs, text box’s, check box’s etc.

The dropdowns will be powered from the db so ideally we would call a method and pass in a pageCode this page code will then determin what needs to be rendered i.e

I pass in pageCode = 1, and it knows that It needs to load content for three drop downs

I pass in padeCode = 2, and it knows that it needs to load content for only one drop down

How can I go about setting something like this up within VS?

1. Partial view for loading the controls based on page code. if less no os page codes, you can manipulate in one partial view. if more page codes create no of patial views
2. One main view for ajax form, dropdown and a div to load partial view based on dropdown selection
3. assign onchange attribute to dropdown with value of ‘this.form.submit();’
4. on action to be requested on change of dropdown  return a partial view

I was thinking partial views for each section would be a good call, that way when the user has chosen something and pressed submit I’ll pass in the values to the DB Save them and return the Partial View name and render that on the page with the appropriate
model.

Just to go a bit deeper in to this question, I have the one ActionResult which is shown here

        [HttpGet]
        public ActionResult Description(string view)
        {
           // "view" will contain the name of the partial view I need to load
           // Ideally I would like to post the values entered back to the description below
           // But I'm unsure on how to determine what has been entered and where to sent it when its been posted

            return View();
        }

        [HttpPost]
        public ActionResult Description(SomeModel model)
        {

           // What model has been filled in? 

            return View();
        }

is the above possible?

It looks possible
Are the models are inherited from a common interface or abstract classes?

Harrison.Scott

[HttpPost]
        public ActionResult Description(SomeModel model)
        {

           // What model has been filled in?

            return View();
        }
[HttpPost]
public ActionResult Description(object model)
{

    if (model.GetType() == typeof(model1))
    {
        //determine that model1 posted
    }
    else if (model.GetType() == typeof(model2))
    {
        //determine that model2 posted
    }

    return View();
}

Your have to excuse me but when you say model1 that would be the name of my actual model correct?

Example of a view model

public class ViewModel{

public TestModel1 test1 {get;set;}
public TestModel2 test2 {get;set;}

}

Then in the controller I would say

[HttpPost]
public ActionResult Description(object model)
{

    if (model.GetType() == typeof(TestModel1))
    {
        //determine that model1 posted
    }
    else if (model.GetType() == typeof(TestModel2))
    {
        //determine that model2 posted
    }

    return View();
}

?

Harrison.Scott

when you say model1 that would be the name of my actual model correct?

What u understood is right.

with the example you provided above can I so the same with the view? i.e

@model object ?

If so how would I get the properties out of it? 

you need to send the particular model

Leave a Reply