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 14 posts 95 karma points
    Apr 21, 2024 @ 17:45
    Craig P

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


    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 571 posts 2177 karma points
    Apr 21, 2024 @ 22:23
    Yakov Lebski

    I think you have 2 ways

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


      var formFilterKeyword = Context.Request.Form["Keyword"]
  • Craig P 14 posts 95 karma points
    May 17, 2024 @ 17:34
    Craig P


    Thank you for the reply, It's taken me a while to get back round to this, but still get an error:

    > System.InvalidOperationException: Incorrect Content-Type:     at
    > Microsoft.AspNetCore.Http.Features.FormFeature.ReadForm()    at
    > AspNetCore.Views_Contact.ExecuteAsync() in
    > C:\inetpub\wwwroot\UmbracoLive\myproject\live\Views\form.cshtml:line
    > 11    at
    > Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage
    > page, ViewContext context)    at
    > Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage
    > page, ViewContext context, Boolean invokeViewStarts)    at
    > Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext
    > context)    at
    > Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext
    > viewContext, String contentType, Nullable`1 statusCode)    at
    > Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext
    > viewContext, String contentType, Nullable`1 statusCode)    at
    > Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext
    > actionContext, IView view, ViewDataDictionary viewData,
    > ITempDataDictionary tempData, String contentType, Nullable`1
    > statusCode)    at
    > Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext
    > context, ViewResult result)    at
    > Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext
    > context)    at
    > Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker
    > invoker, Task lastTask, State next, Scope scope, Object state, Boolean
    > isCompleted)    at
    > Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed
    > context)    at
    > Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State&
    > next, Scope& scope, Object& state, Boolean& isCompleted)    at
    > Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()

    I used to have no problems doing this with V8 but it's really frustrating? I've seen lots of posts online suggesting something similar to your suggestion above, none of them seem to work at all? Any Idea?

Please Sign in or register to post replies

Write your reply to: