Telerik MVC UI Extensions

  • Thread starter Thread starter Guest 20221009
  • Start date Start date
G

Guest 20221009

Guest
So I chose the Telerik grid over MVCContrib and I have had to add code for reordering rows on the fly.

I am doing this through a template column:

columns.Template(c => @Html.ActionLink(c.CampaignFieldID == Model.FirstOrDefault().CampaignFieldID ? "Down" : "Up", "Order",
new
{


id = Model.Single(d => d.CampaignFieldID == c.CampaignFieldID).CampaignFieldID,
direction = Model.FirstOrDefault().CampaignFieldID.Equals(c.CampaignFieldID) ? "down" : "up"
})).Column.Title = "Order";

My stuff works fine, but fails when the grid goes into insert mode. I am unable to pass an id parameter since my Model for the new record is null.

I get "System.InvalidOperationException: Sequence contains no matching element"

I tried testing for a null model property and I can bring up the insert mode fine, but the actual insert fails.

please help :cry:
 
I added:

id = Model.Equals(null) ? Model.Single(d => d.CampaignFieldID == c.CampaignFieldID).CampaignFieldID : 0

Seems to work, but i think my insert controller is faulty.
 
I ditched the steps above in favour of:

columns.Template(c => @Html.ActionLink(c.CampaignFieldID == ViewBag.First ? "Down" : "Up", "Order",
new
{
id = c.CampaignFieldID,
direction = c.CampaignFieldID.Equals(ViewBag.First) ? "down" : "up"
})).Column.Title = "Up";

columns.Template(c => @Html.ActionLink((c.CampaignFieldID != ViewBag.First && c.CampaignFieldID != ViewBag.Last) ? "Down" : " ", "Order",
new
{
id = c.CampaignFieldID,
direction = c.CampaignFieldID.Equals(ViewBag.First) ? "down" : "down"
})).Column.Title = "Down";

I am using good old LINQ to fill up two ViewBag dynamics for my first and last rows. This eliminates the need to use Model. My insert controller was also skewed, well, more of a stupid mistake on my part :(
 
Top
Sign up to the MyBroadband newsletter
X