adriaanp
adriaanp

Reputation: 2074

Server side code in Razor view

Is there a way to create functions like these in the Razor view engine?

@{
    View.Title = "Clients";

    private string GetRowClassName(RowStatus status)
    {
        if (status == Model.SelectedStatus)
            return "selected";
        return string.Empty;
    }
}

Upvotes: 2

Views: 1748

Answers (1)

marcind
marcind

Reputation: 53183

You can do this:

@functions {
   private string GetRowClassName(RowStatus status) {
     if (status == Model.SelectedStatus)
       return "selected";
    return string.Empty;
  }
}

You could also look into the @helper syntax but in this case @functions is probably better.

Upvotes: 6

Related Questions