Net Fiddle problema with route

122 Views Asked by At

i'm problem with Net Fiddle use MVC. When i click the button "Ordernar por Nome" result in Erro page, but in my PC works well.

https://dotnetfiddle.net/HCLpdv

The problem code is:

[HttpGet]
public ActionResult Index()
{
    listPessoas = new List<Pessoa>();
    populatePessoas(listPessoas);


    CountSituacao();
    ViewData["pessoas"] = listPessoas;

    return View();
}
[HttpGet]
public ActionResult OrderByName()
{

    OrderList();
    ViewData["pessoas"] = listPessoas;

    return View("Index");
}

My problem is that when Net Fiddle executes OrderByName action it says that it can't find view

Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

I would say that this is a specific of Net Fiddle as we don't have actual file system there and it has only one view. And UI doesn't allow to specify name for that view.

We treat view name dynamically based on current action name. In your case you have two actions Index and OrderByName, so if both methods will use default View() without specifying viewName, then it will be working fine as by default we render view based on current executing action.

It's not so correct behavior, but otherwise we need ability to specify a couple of views with names, that we can't do right now.

So to fix your issue you just need to use such action code:

[HttpGet]
public ActionResult OrderByName()
{
     OrderList();
     ViewData["pessoas"] = listPessoas;
     return View("OrderByName");
}

Or just empty View()