locked
Prevent a razor page being refreshed RRS feed

  • Question

  • User-300319147 posted
    Hi guys,
    I am creating a razor app and in it I have a main page with a partial page within it, the partial page contains some static data in a table, the problem I’m having is that when the main page is posted back to the server the partial page is refreshed and I lose my static data, how do I prevent my partial page being refreshed when the main page is does a post back ?
    Monday, June 10, 2019 9:58 AM

Answers

  • User-821857111 posted

    Presumably, you are populating the Partial in your OnGet method, but not in your OnPost method? If so, make sure that you repopulate it in the OnPost method as well.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 10, 2019 12:46 PM

All replies

  • User-1038772411 posted

    Hi, Devbill

    In the given solutions Page will be refreshed but will reduce server call and will not call action again and again.

    In MVC4 one of best way you can achieve this purpose it by using Caching.

    [OutputCache(Duration=30)]
    public ActionResult FEATURE_1_URL(){}

    so by specifying time it will store your result in caching so when you click next time ActionLink it will give you result from Caching data as per duration time and it will reduce request to the server.

    This can be use for fast response.

    Thanks.

    Monday, June 10, 2019 10:45 AM
  • User753101303 posted

    Hi,

    You still may want to dig a bit deeper before applying a solution:
    - if really "static" data they are shared by all users, is this what you want ? If  not you could end up with issues when multiple users are using your site.
    - if really "static" they are not supposed to be lost so it seems some kind of flaw in your current logic

    Before blindly applying some kind of solution, it seems to me you should give this a closer look to make sure your design is correct and a solution won't workaround (maybe just temporarily) your issue rather than  really solving it...

    Monday, June 10, 2019 11:02 AM
  • User-300319147 posted
    Maybe I need to look at saving the static or temporary data and then reloading when the partial is refreshed.
    Monday, June 10, 2019 12:35 PM
  • User-821857111 posted

    Presumably, you are populating the Partial in your OnGet method, but not in your OnPost method? If so, make sure that you repopulate it in the OnPost method as well.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 10, 2019 12:46 PM
  • User-821857111 posted

    In MVC4 one of best way you can achieve this purpose it by using Caching.

    [OutputCache(Duration=30)]
    public ActionResult FEATURE_1_URL(){}

    This question is about ASP.NET Core. There is no OutputCache attribute in .NET Core.

    Monday, June 10, 2019 12:51 PM