passing data(Id) with redircetToAction to url usin

2019-07-30 14:32发布

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

0条回答
登录 后发表回答