This is a migrated thread and some comments may be shown as answers.

[Solved] CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement

2 Answers 256 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jaymie
Top achievements
Rank 1
Jaymie asked on 26 Sep 2011, 11:04 AM
So, I have this bit of code:

@(Html.Telerik().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Template(o => {               
                string url = "~/Content/Graphics/{0}";
                string name = "Twitter";
                switch (o.type_id)
                {
                    case 1:
                        // Twitter
                        url = string.Format(url, "twitter.png");
                        name = "Twitter";
                        break;
                    case 2:
                        // Facebook
                        url = string.Format(url, "facebook.png");
                        name = "Facebook";
                        break;
                    case 3:
                        // Linked In
                        url = string.Format(url, "linkedin.png");
                        name = "Linked in";
                        break;
                    case 4:
                        // Google Plus    
                        url = string.Format(url, "Google+.png");
                        name = "Google Plus";              
                        break;
                    default:
                        url = string.Format(url, "twitter.png");
                        name = "Twitter";
                        // Twitter
                        break;
                }
                @<img src="@Url.Content(@url)" alt="@name" width="32" height="32" />;
            });
            columns.Bound(o => o.from_user).Title("From");
            columns.Bound(o => o.text).Title("Message");
            columns.Bound(o => o.date_created).Title("Date").Format("{0:d}");       
            columns.Template(@<text> @Html.ActionLink("Edit", "Edit", new { id = item.id} ) |
                                 @Html.ActionLink("Delete", "Delete", new { id = item.id } ) |
                                 @Html.ActionLink("Approve", "Approve", new { id = item.id }) 
                         </text>).Width(150).Title("Actions");
 
        })
        .CellAction(cell =>
        {
            if (cell.Column.Member == "Approved")
            {
                bool approved = cell.DataItem;
                if (approved) {
                    cell.HtmlAttributes["style"] = "background-color: Red;";
                }
            }
        })
        .Groupable()
        .Sortable()
        .Pageable()
        .Filterable()
)


What I am trying to achieve is a different image based upon the type_id. But I just can't get it to work.
The error message I am getting is:

CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement

And it is pointing to this line:

@<img src="@Url.Content(@url)" alt="@name" width="32" height="32" />;

More specifically the first @. I have tried @<text> and @() but it is always the same.
Could someone give me a hand please.

2 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 26 Sep 2011, 12:02 PM
Hello Jaymie,

This is how your server template might look.
.Columns(columns =>
        {
            columns.Bound(d => d.ID);
            columns.Template(
                @<text>
                    @{
                        string url = "~/Content/2011.2.914/Default/{0}";
                        string name = "loading";
                        if (item.ID % 2 == 0)
                        {
                            url = String.Format(url, "loading.gif");
                            name = "loading";
                        }
                        else
                        {
                            url = String.Format(url, "editor.png");
                            name = "editor";
                        }
                    }
                    <img src="@Url.Content(url)" alt="@name" width="32" height="32" />
                </text>
            );
        })


Regards,
Nikolay Rusev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Jaymie
Top achievements
Rank 1
answered on 29 Sep 2011, 11:12 AM
Thank you, that worked perfectly :)
Tags
Grid
Asked by
Jaymie
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Jaymie
Top achievements
Rank 1
Share this question
or