Megrez7 Megrez7 - 15 days ago 5
C# Question

Code explanation needed

I am vb.net familiar. Have a razor c# piece of code. When through pages of documentation but I cannot find out what does this code do? Understand that runs function IsSelected of Html class but what is the meaning of argument passed to it?

<li class="@Html.IsSelected(controller: "Dashboards")>

Answer

if I understood correctly you want to under stand what this does

 @Html.IsSelected(controller: "Dashboards")

@ tells razor to output the following to the html code by executing

Html.IsSelected

the parameter is a Named or optional parameter. It is basically saying sets the value of parameter with name "controller" to "Dashboards"

The function's definition might be like

IsSelected(int notUsed = 0, string notUsed2 = null, string controller = "dead beef")

so that you can save yourself some typing instead calling IsSelected(0, null, "Dashboards")