0

Is it a good way to use routed values for column name, page and sort dir or are there better ways to keep the webgrid settings alive?

Currently it looks like this:

@Html.ActionLink("Delete", "DeleteEntry", new { id = item.Id, sortdir, sort = webgrid.SortColumn }, new { @class = "LoeschenImgStyle", onclick = "return confirm('You're sure?');" })

And my controller method looks like this:

public ActionResult DeleteEntry(Guid id, string sortdir, string sort)
{
    _einheitenRepository.DeleteIt(id);
    return RedirectToAction("Index", new { sortdir, sort });
}

Are there better alternatives to do the same?

Thanks :)

Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
Jannik
  • 2,310
  • 6
  • 32
  • 61
  • I would think it is the correct way, since it allows users to easily share links to a certain page. That wouldn't be possible if for example the data was passed via POST of cookies. – jao Apr 30 '13 at 11:25

1 Answers1

1

There's nothing really wrong with what you already have, but you could clean it up slightly by just using a Model in place of those parameters. You could first have a base model that included your paging info, something like:

public abstract class ModelBase
{
    public string SortDir { get; set; }
    public string Sort { get; set; }
}

Then for this instance (let's say it's an item), you could have this model:

public class ItemModel : ModelBase
{
    public int Id { get; set; }
    //rest of the properties in your ItemModel
}

Then your ActionResult would look cleaner, like so:

public ActionResult DeleteEntry(ItemModel model)

And your ActionLink could populate that model, by doing:

Html.ActionLink("Delete", "DeleteEntry", new { Id = item.Id, SortDir, Sort = webgrid.SortColumn }, new { @class = "LoeschenImgStyle", onclick = "return confirm('You're sure?');" })

Then you'd end up with an auto-populated model instance every time, saving you from adding excessively long parameter lists in your action methods.

Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148