Hello,

I'm building an application in MVC which allows people to upload and sell there items, (Like ebay but on a much smaller scale)
I currently have a view where they choose the categorie they want to place there item in, when they click ok I pass in the selected values to a view and at this point I need to determin what view to render allowing the user to enter some more information

I currently have a dictionary as follows

public string ReturnView(string categoryId)
    {
        var views = new Dictionary<string, string>
        {
            {"Value1", "View1"},
            {"Value2", "View2"},
            {"Value3", "View3"},
            {"Value4", "View4"},
            {"Valuen", "Viewn"}
        };

        string selectedView = views[categoryId];

        return selectedView;
    }

This returns the view (the above is for testing I havent named my views View1, 2 etc) but each view has a different model associated with it, and im unsure how I can extend this to cater for the model ideally i would like something like this

public string ReturnView(string categoryId)
    {
        var views = new Dictionary<string, string>
        {
            {"Value1", "View1", Model1},
            {"Value2", "View2", Model2},
            {"Value3", "View3", Model3},
            {"Value4", "View4", Model4},
            {"Valuen", "Viewn", Model5}
        };

        string selectedView = views[categoryId];

        return selectedView;
    }

A few people have said use "If" statements but in some categories I have 15 child categories and having a "IF" statement would look quite ugly, And I prefer to do it the proper way.

If someone can help me achieve this I would really appreciate it.

Ok, I have a solution which will make things easier I think, the value I pass in will be the name of the view so my dictionary will look like this

public string ReturnView(string value)
        {
            var views = new Dictionary<string, string>
        {
            {"some_View","Model1" },
            {"some_View2","Model2" },
            {"some_View3","Model3"},
            {"some_View4","Model4" },
        };

            string selectedView = views[value];

            return selectedView;
        }

How can I modify the dictionary instead of <string,string> it needs to be <string,model> can someone help with the syntax please

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.