Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So this is the view :

div class="row">
    <div class="col-md-6" style="width:auto">
        @foreach (var module in Model)
        {
            if (module.Placeholder == "left" && module.PageId == "contact" && module.Control == "Tabelar2")
            {
                Html.RenderAction("Tabelar2", "ContentHtml", module.Control );
        }


            <br />
        }
    </div>



I have a field in the database Control that saves names of controls/actionresults/views , example
module.Control
shows 3 words(actionresults/views names) from database , NewsList and Tabelar and Tabelar2.


In the above code , i say manually , but how can i do it to , if :

if (module.Control == "Tabelar2") //tabelar2 is just a text , but in fact the name of an actionresult in the controller
{
Html.RenderAction("Tabelar2", "ContentHtml", module.Control );
// than render module.control automatically

}


So , based on module.control , then render that control and recognise it as actionresult/view , exmaple NewsList.chtml , and render this view inside the div.

What I have tried:

i just explained above the question.
Posted
Comments
David_Wimbley 29-Aug-17 11:14am    
I think i'm a little confused but it looks as though your trying to write an if statement, which contains variables for your action/controller names that you are trying to pass into .RenderAction.

Why can't you just call one .RenderAction method and pass all variables into instead of writing an if statement to see if your action/controller match, and then hard coding those same values you just did in the if statement.

Meaning what I think i see you doing is

if(moduel.Control == "Tabelar2")
{
Html.RenderAction("Tabelar2", "ContentHtml", module.Control)
}


Why not just have properties of your model of say .ActionName and .ControllerName then all you'd have to do is


Html.RenderAction(model.ActionName, model.ControllerName, module.Control)


And not have to worry about writing tons of if statements for, based on your comment history, is a CMS. If you are writing a CMS you need to allow most flexibility so anytime you have to add a condition to that group of if statements, you aren't necessarily allowing the most flexibility possible to your end user.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900