Help with AJAX not working with ASPX-based CMS
So here's the background: I installed Orchard CMS in a windows box running IIS 7 and .NET 4. Everything works perfectly.
There is a contact form, pretty straight forward, the only difference is that the submission is done through Ajax.
The Ajax script is pretty simple and it works just fine when tested outside the CMS environment
var dataString = 'fName='+ fName + '&fTitle='+ fTitle + '&fCompany='+ fCompany + '&fEmail=' + fEmail + '&fPhone=' + fPhone + '&fOptout=' + fOptout;
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "/form_pc_aspx",
data: dataString,
//changed to error for testing purposes. test is error
success: function() {
$('.error').hide();
$('#calc-blind').hide();
$('#calcForm').fadeIn();
}
});
return false;
The problem is that once the page is placed in the CMS, the /form_pc.aspx is blocked with a 404 so the code will not be processed.
I have asked this question in the Orchard Forum with no luck.
It seems to be a matter of permissions, but I don't know how to allow direct access to this form_pc.aspx file or how to allow the Ajax to submit the form.
Any help pointing me in the right direction will be appreci开发者_如何转开发ated.
Rather than Post to an aspx page inside of Orchard you should post to a Controller that you put inside one of your modules. By using the MVC helpers you can find the url of your action inside your controller and do the ajax call that way. I know that it works as that is what I am doing inside one of my modules I created to learn Orchard.
Orchard CMS is built upon ASP.NET MVC 3, so, by default, there are no URLs ending with .aspx. You cannot just place the WebForms .aspx file and make it work. I'd recommend you to read this article about mixing ASP.NET MVC with WebForms. Orchard CMS is just an ASP.NET MVC app (fancy, though) so this would be doable for sure.
Could you please provide more details about your setup and what exactly do you want to achieve? It would help me provide you a more specific solution.
At first sight it looks like there's something wrong and could be easily achieved without any ninja-style-mixing-mvc-and-webforms stuff:)
精彩评论