3

In .NET Framework MVC, I could do it with the following codes:

 public class HomeController : Controller
{
    public ActionResult Index()
    {
        Student student = new Student()
        {
             Id = 2, Name = "Mike"
        };

        return View("About", student);
    }
}

How do I convert the code above to Razor Pages (not MVC). At the moment for Razor Pages, I can only return the object to the same Page by making use the of the [BindProperty] attribute and the return is just basically return Page() and for redirect, I would just use return RedirectToPage("/Home/About");.

2
  • return RedirectToAction("Controller","About"). And create a new Action About to call view "About":that you want. Commented Sep 3, 2019 at 6:24
  • RedirectToPage is the correct method. You can use TempData (learnrazorpages.com/razor-pages/tempdata) to pass the student to the About page when you redirect. Commented Sep 3, 2019 at 8:03

1 Answer 1

4

I found out how already.

return new RedirectToPageResult("About", student);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.