locked
MVC @Request["someName"] is there an equivalent in Core Razor Pages RRS feed

  • Question

  • User-943250815 posted

    In MVC after postback I can persist a hiddenfield value using

    <input type="hidden" id="hdfSearchType" name="hdfSearchType" value="@Request["hdfSearchType"]" />

    How can I have same behavior in Razor Pages other than using page property like

    <input type="hidden" asp-for="hdfSearchType" name="hdfSearchType" />

    Wednesday, August 14, 2019 6:52 PM

Answers

  • User-821857111 posted

    Why don't you want to use PageModel properties or tag helpers?  If you want to continue to use Request["..."], you might as well not use Razor Pages at all. 

    But if you are set on going that route, you could try Request.Query["hdfSearchType"].ToString()

    If it's a form field rather than a query string value, you will have more hoops to jump through. A PageModel property is the simplest option.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 14, 2019 7:39 PM

All replies

  • User-821857111 posted

    Why don't you want to use PageModel properties or tag helpers?  If you want to continue to use Request["..."], you might as well not use Razor Pages at all. 

    But if you are set on going that route, you could try Request.Query["hdfSearchType"].ToString()

    If it's a form field rather than a query string value, you will have more hoops to jump through. A PageModel property is the simplest option.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 14, 2019 7:39 PM
  • User-943250815 posted

    I´m already using PageModel Property.
    In my scenario I have a grid filter and paging where I have to persist filter & page value between posts. So hidden fields are set and form submitted by javascript.
    Ok, lets deal with Page Properties.


    I´m VB & Webforms, in last weeks I have been playing around C#, MVC, Razor Pages and Core.
    I´m really surprised how they are different and (at some point) some basic MS documents are not clear enough.
    By the way info provided by your websites are very helpfull.

    Wednesday, August 14, 2019 9:45 PM
  • User-821857111 posted

    So have you resolved your issue or do you still require assistance?

    Thursday, August 15, 2019 8:52 AM
  • User-943250815 posted

    Done.
    Thanks

    Thursday, August 15, 2019 3:22 PM