Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Craig P 13 posts 94 karma points
    1 week ago
    Craig P
    0

    Error trying to post data to a page in v12 and retrieving using Request.Form

    Hi,

    I have a form on one of my Umbraco pages which posts back to itself (it's for a filter)

    I have done this before on earlier versions of Umbraco but it's just not allowing me to do this on Version 12

    var formFilterKeyword = Request.Form["Keyword"].ToString();
    

    I am getting this error:

    error CS0103: The name 'Request' does not exist in the current context"

    when trying to get the keyword from the form field using the code above. As I said, I have used this before on v8. I realise this is likely to be a new .net core issue, how would I do it on v12? Looking for the simplest solution.

    Thanks in advance :)

  • Yakov Lebski 554 posts 2119 karma points
    1 week ago
    Yakov Lebski
    0

    I think you have 2 ways

    @inject Microsoft.AspNetCore.Http.IHttpContextAccessor HttpContextAccessor
    
    var formFilterKeyword = HttpContextAccessor.HttpContext.Request.Form["Keyword"];
    

    or

      var formFilterKeyword = Context.Request.Form["Keyword"]
    
Please Sign in or register to post replies

Write your reply to:

Draft