0

hello I'm trying to pass the new posted value to a different view with the new value id at the url using RedirectToAction but I'm getting the wrong Url . Just like here in SO ,that you get redirect to your Q. after submit. the Url I'm suppose to get is http://localhost:1914/en/evntes/index/60

MyCode(Controler= VoosUp)

public ActionResult Create()
    {
        var viewModel = new LectureFormViewModel
        {
            Genres = _context.Genres.ToList(),

        };
        return View("Gigform", viewModel);
    }

    [Authorize, HttpPost]
    public ActionResult Create(LectureFormViewModel viewModel)
    {
        if (!ModelState.IsValid)
        {
            viewModel.Genres = _context.Genres.ToList();

            return View("Gigform", viewModel);
        }


        var lectureGig = new LectureGig
        {
             //Prametrest
        };

        _context.LectureGigs.Add(lectureGig);
        _context.SaveChanges();

        // return this.RedirectToAction( "events", (c=>c.Index(lectureGig.Id)); //Compiler Error
        return RedirectToAction("index", "Events", new { id = lectureGig.Id });//Ok Id 60
    }

Events/Index

public ActionResult Index(int id)//OK id=60
    {
        var lecturegig = _context.LectureGigs.Include(g => g.Artist)
           .Include(g => g.Genre)
           .SingleOrDefault(g => g.Id == id);
        if (lecturegig == null)
            return HttpNotFound();
        var viewmodel = new GigDetailViewModel { LectureGig = lecturegig };


        return View("index", viewmodel);
    }

Url i'm getting :http://localhost:1914/en/VoosUp/Create and the view is correct

Assaf Our
  • 611
  • 3
  • 9
  • 25
  • what and where ur getting problem –  Jan 03 '17 at 10:29
  • the url is incorrect http://localhost:1914/en/VoosUp/Create instead of http://localhost:1914/en/evntes/index/60 while the view is correct . – Assaf Our Jan 03 '17 at 10:33
  • Are you posting using AJAX? If yes, take a look at this answer [RedirectToAction does not change the browser URL](http://stackoverflow.com/questions/12353748/redirecttoaction-doesnot-change-the-browser-url). – Georg Patscheider Jan 03 '17 at 10:56
  • @GeorgPatscheider ,I have remove the ajax posting and that's true without the ajax post it's working , but data_ajax ="false" , is not changing it .and I do need to post ajax . – Assaf Our Jan 03 '17 at 12:06
  • Maybe this technique works: http://stackoverflow.com/a/7929108/1450855 – Georg Patscheider Jan 03 '17 at 12:45
  • @GeorgPatscheider It doesn't look like it can help but this one look promising http://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery-ajax-call/1534662#1534662 , im just not sure how to use it in my case – Assaf Our Jan 03 '17 at 12:55

0 Answers0