I've encountered a pretty weird situation, I'm using Win7, VS2010, ASP.NET MVC2, jQuery. I have a simple form a textarea and a button doing a .post() ajax call to server, pretty simple setup.
It works when I input plain text in the textarea, but if I mix html tags like bold, then it works sometimes!!
I do have [ValidateInput(false)] on the action method and ValidateRequest="false" on my view, the things is that what I have does work, sometimes.
So when I debug it and mix html tag and submit, it does go into the the action method correctly, sometimes. While other times, like when not in debug, it just does not stop in the action method at all.
Very Werid! Just thought to ask if anyone else had this problem before?
It turns out that make this to work I need to have the following 3 things on my ASP.NET MVC app ready,
ValidateRequest="false" on the view
[ValidateInput(false)] on the action method
<httpRuntime requestValidationMode="2.0"/> on the web.config
The last thing is what I missed, I found this out by using FireBug which returned the entire asp.net Yellow Screen in html in its console.
Interesting thing is that without the last item, when you input html tags in the textarea the app should NOT work but throw some security exception, but it worked when I debugged my app which made the whole thing confusing.
Related
Let me first be clear about what I'm not asking. I can see that the native ASP.NET MVC Ajax.BeginForm does not handle posting files from within an AJAX form post. There are answers I've seen that seem to establish this fact, and to offer an assortment of workarounds via jQuery plugins, etc:
Ajax.BeginForm in MVC to upload files
File upload with ajax in asp.net mvc
I'm not asking whether it can't be done, and I'm not asking for a workaround. I'm hoping someone can explain why it can't be done.
How is the AJAX form post being handled in MVC such that file inputs do not post? I guess I had always assumed that it was being handled at a base level just like a full post, but with some javascript trimmings that prevented a full page reload. Apparently that's not the case. Is the form submitted via javascript something like jQuery's $('#form').submit()? What's happening under the covers?
Does anyone know of any bugs or other insight to explain why when using MVC4 with jquery mobile, any form that is created using Ajax.BeginForm results in the form being submitted twice to the controller.
I had originally thought that since I am using the js bundling that the same js file might have been being included twice and might be triggering on form submit, however thats not the case, my list of js files are:
jquery-1.6.4.js
jquery-ui.1.8.11.js
jquery.mobile-1.1.0.js
jquery.unobtrusive-ajax.js
jquery.validate.js
knockout-2.0.0.js
MicrosoftAjax.js
MicrosoftMvcAjax.js
MicrosoftMvcValidation.js
Modernizr.js
Within the project Ajax is fully enabled for everything i.e. i'm not disabling anything through mobileinit.
I have not posted any form code because it literally happens with every form - a form with one field and a submit button will cause the submission twice - but only where Ajax.BeginForm is being used.
Html.BeginForm doesn't exhibit any of these problems.
I've been stuck on this for a few days now so any help would be greatly appreciated
jQuery Mobile by default hi-jacks any form submission and performs its own AJAX request. To stop this behavior you can place the data-ajax="false" attribute on any <form> tag. Also make sure to stop the regular behavior of the form so it doesn't submit normally, something like:
$('#my-form').on('submit', false);
Docs: http://jquerymobile.com/demos/1.1.0/docs/forms/forms-sample.html
You could also just use the built-in jQuery Mobile AJAX rather than including extra JS for it. Which would only require you to make the action attributes of the forms to the server-side file to which they posts.
In facebook after I shared something in my wall I get a nice pop message about my activity. Sometimes whenever there is an error with they gave a nice pop about the error. Like this.
I know in facebook everything is about ajax.
I am creating a web application using mvc 3 asp.net. In my web app there is something similar to sharing links like in facebook.
I implemented this feature using ajax and partial views and it is works fine.
When user submit a new link, In my controller action method I update the db and return a partial view finally update my view with nice animation.
Now my problem is how can I give a pop up response while updating my view(facebook wall).
I want to do both of them with the ActionResult.
I not sure this is the correct way to do this.
Briefly what I want is update my view with automatic pop up response. Hope you understand what I want.
Let me know If you need any clarification on this.
Please help me to implement this function.
Thanks !!
Well a "popup" is client-side functionality, not server-side. You can't do it with actionresult per-se.
Perhaps you should return a PartialViewResult from an action method, which is fired by an AJAX call (e.g jQuery).
Then in the callback, set the HTML of a hidden container/div to the partial view's HTML, then show it in a fancy way.
Something like jQModal or jQuery UI dialog is perfect for this.
I found the answer myself. Add Jquery library and unrobustive javascript and
return JavaScript("alert('Some message')");
I've search high and low for an answer to this but unfortunately I'm stuck. The problem is only occuring in Firefox (tested IE, Chrome and Safari also - works fine, no errors of any sort). I'll detail the sequence of events to save posting all my code.
ASP.NET MVC 3 application, basic form loads into a jQuery UI dialog
Custom jQuery to hijax the form submit (serialize the form and then $.post to the server - no compiler errors when debugging and post shows up in Firebug without errors)
Http GET (automatically happens) getting the response object from the server (+ success text and XHR), response is plain HTML in this case (again, shows up in Firebug with no errors)
Custom jQuery to change the HTML of the UI dialog from it's current HTML to the response Html - this is where it fails.
I've used javascript alerts to debug the sequence of events and as soon as the post (and get) is complete, everything just... sort of stops.
As I say, only in firefox! Very odd, just wondering if there's any known bugs with ajax and firefox or anybody has heard of a similar situation?
I must also add, that on other parts of my site, this works perfectly in all browsers! The only difference between this form and the other forms that do successfully complete the function is that the response from this form is the same "page" again but updated rather than a new "page". (I use "page" as I got all this working with Javascript turned off first and for graceful degredation)
HELP! Or laugh, either is fine.
UPDATE
I have tried sending a view with a blank model back as the action result - works in every browser except firefox - firefox retains the values from the previous post! And then I got to thinking - that's a trait of firefox isn't it? And maybe that's why the original "re-direct" html response doesn't work?? I think it's time to give up and let people know they can't use Firefox for that particular function!
Ok so I'm answering my own question.
The only way I found to get round it is to use $.ajax instead of $.post and to use the option async : false
Hope this helps somebody.
Rob
Have you tried adding the attribute [OutputCache(Location = System.Web.UI.OutputCacheLocation.None)] to your Action for your GET? It sounds to me like a caching issue.
I want to save html markup in my database for a field from an ASP.Net MVC2 application. Upon reading I found that using the [ValidateInput(false)] attribute lets you do that. But it is not working for me. The data comes from the extjs htmleditor form element.
Anyone has any ideas? Is there something else I need to do? Any setting in web.config?
see ASP.NET Request Validation Exception Even When Validation Is Disabled