Try our conversational search powered by Generative AI!

POST from CMS Admin MVC page


Hi Fellows,

I'm implementing a CMS admin page using the ASP.NET MVC 5 for the UI (with EPiServer CMS 11.19). I'm able to include the related CSS and JS in order to use the CMS admin look & feel. My problem is that it seems I'm unable to issue a POST request: on the view, there is a form with an input filed of type "file" and a submit button (input of type "submit"). Clicking the submit button does GET-request to the controller and not the expected POST-request. Thus I'm unable to post the form with the file-field. Regardles of the input control, that should issue the POST-request (anchor; normal button with JS for the onclick event, where the form' submit gets called;), the controller receives a GET-request insted of the POST-one.

How can I issue POST-request with the form?

Many thanks for your attention.

Oct 27, 2020 18:22

Have you stated correct method on the form?

<form method="post">
Oct 28, 2020 8:24

Hi @Johan Peterson,

my form looks like that bellow:

@using (Html.BeginForm("MyPostAction", "MyController", FormMethod.Post, new {id= "myForm",enctype = "multipart/form-data", @class = "epi-FormArea"}))
<div class="epi-buttonContainer">
<span class="epi-cmsButton">
<input class="epi-cmsButton-text epi-cmsButton-tools epi-cmsButton-Import" id="submitButton" type="submit" value="Submit">
<span class="epi-cmsButton">
@* <input class="" id="submitButton2" type="button" value="Import #2" onclick="document.getElementById('myForm').submit()"> *@
<a href="javascript:document.getElementById('myForm').submit()">Submit!</a>

None of the submit trials above hit the POST-method MyPostAction. That action does not have a HttpGet counterpart, so the error is 404. If I use the Index Action instead (which has HttpGet and HttpPost variants), then the click on the submit-button (link) hits the GET-version of the action.

Many thanks and kind regards.

Edited, Oct 28, 2020 9:29

The form seems correct. And are you sure that this is a GET, is that what the browser console (F12 tools) says as well?

Oct 28, 2020 9:34

Hi @Johan Peterson,

I can see three entries in the Network tab:

  • first is a POST request with status code 301 (moved permanently), the initiator is "Other"
  • second is a GET request with the same status - 301, the initiator is MyController
  • third is a GET request with status 404 (not found), the initiator is the Route / MyController

This leads me to the conclusion, the route seems to be not correct... I've configured it this way:

new { controller = "MyController", action = "Index" } );

Do you recognize here something wrong?

Many thanks and kind regards.

Oct 28, 2020 10:20

Depends on where you have put your controller (in which namespace). Please see

Oct 28, 2020 10:53

Here's the controller's declaration:

namespace MyApplication.Controllers
using System.Web.Mvc;
using EPiServer.PlugIn;
using EPiServer.ServiceLocation;
using Models.ViewModels;

[GuiPlugIn(Area = PlugInArea.AdminMenu, DisplayName = "Custom Tool Plugin", Url = "/MyController")]
[Authorize(Roles = "CmsAdmins, WebAdmins")]
public class MyController : Controller


Oct 28, 2020 11:38

Your controller must have an action called MyPostAction that accepts a posts as well.

Oct 28, 2020 13:04

Yes, the controller has that action, also it has the GET+POST Index actions.

Oct 28, 2020 13:28

Is the form posted to the correct URL? Either inspect the html and check the action attribute on the form or network tab in the F12 tools.

Oct 28, 2020 13:32

I think so - the form gets posted to a URL like this http://localhost:12345/MyController/MyPostAction (or in case of using the Index action http://localhost:12345/MyController). But the question here would be why the POST comes from "Other" and gets responded with 301 from the server... To my understanding, this would really mean the controller has not been configured correctly... But how to configure it correctly?! And finally then why the GET request goes straight to the right controller action? Like on the same controller the GET is correct, the POST is wrong... 

Edited, Oct 28, 2020 13:43

Do you have any rewrite rules that are doing redirects? A 404 handler? Other routes that triggers before this one? Try putting this route first in the route table.

Oct 28, 2020 13:49

For handling 404-errors, I'm using the BVN 404 Handler:

<bvn404Handler handlerMode="On">

And I also have a redirect.config with redirect rules (good catch from your side!), whose last action on the configured rule (one single rule has been configured) is:

<action type="Redirect" url="{ToLower:{URL}}" redirectType="Permanent" />

And this seems the reason why the redirection gets status 301 (permanent) and it seems the controller MyController has not been listed in the conditions block of the rule... I'll look at this and will change the rule's conditions to see if when I add the controller to the conditions, it will start to behave correctly... Will report here as soon as I've results...

Many thanks and kind regards.

Oct 28, 2020 14:09

Thanks @Johan Peterson, for your help on solving my problem.

I can confirm the problem has been solved after the redirect rule has been extended with a condition for the MyController route.

Kind regards.

Oct 28, 2020 15:09
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.