Question

I'm using the MVC 4.0 mobile template for a project and I run into an odd problem with the default scaffolding/template. I created a simple model:

public class Person
{
    public int Id { get; set; }
    [Required]
    public string Name { get; set; }
}

then I created a simple Controller with an Index action and a Create action:

public ActionResult Index()
    {
        List<Person> persons = new List<Person>();
        return View(persons);
    }

public ActionResult Create()
    {
        Person p = new Person();
        return View(p);
    }

    //
    // POST: /Person/Create

    [HttpPost]
    public ActionResult Create(Person p)
    {
        try
        {
            // TODO: Add insert logic here
            //empty

            //return Redirect("/Person/Index");
            return RedirectToAction("Index", "Person", null);
        }
        catch
        {
            return View();
        }
    }

Generated the views for the two actions: for Index I generated a List view and for the Create I generated a Create view. Now the problem is that after I create a new product it should redirect to Index view which in an odd way it does but the url remains /Person/Create and then when I click the 'Create New' link on the Index view nothing happens. (create new link as it was generated: @Html.ActionLink("Create New", "Create") )

I'm thinking this is a bug but I didn't found anything online yet.. Any recommendations as to how I can make this work?

Thanks.

Was it helpful?

Solution

There is a workaround: jQuery Mobile/MVC: Getting the browser URL to change with RedirectToAction

Additionally, the page was not refreshing (I used IE) so I had to follow this answer in order to get the page to be refreshed on IE after RedirectToAction: How to stop MVC caching the results of invoking an action method?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top