0

When the user has javascript disabled, I would like to make the ajax.beginform not do anything at all, instead of submitting a regular full-page post request. What is a proper way to accomplish this?

1 Answer 1

1

No matter what you do if there's a form tag in the page and javascript disabled it can always be submitted. Even if you remove the action attribute it will submit to the same page. So you could use the <noscript> tag to provide an alternative markup to users with javascript disabled. Another possibility is to hide the submit button with CSS and show it with javascript (so that only users that have JS enabled can see it) but this is not ideal because the form could still be submitted by pressing Enter while typing inside an input.

I think a better way would be to leave the form submit a regular request and in your controller action handle this case and react accordingly:

if (Request.IsAjaxRequest())
{
    // act as normal
    return PartialView();
}
else
{
    // the user had javascript disabled
    return View();
}
Sign up to request clarification or add additional context in comments.

2 Comments

if you look at SO, when you have JS disabled, you can't vote, favorite etc. You can click on it, but it doesn't do anything. Maybe it's doing something behind the scenes
What it is doing behind the scenes is that it is using a span for the buttons instead of submit buttons and attaching click handlers unobtrusively to them using jQuery. So if the user has javascript disabled those click handlers are not attached and nothing happens because you are clicking on a simple span.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.