Ajax.BeginForm replaces whole page with partial view - ajax

I'm having problems using Ajax.BeginForm() in my simple ASP.NET MVC application. I've searched SO for solution but nothing I found seems to help.
I've created a new project using the default Visual Studio 2015 template. I've changed the Index.cshtml file to:
#{
ViewBag.Title = "Home Page";
}
<div class="jumbotron">
<h1>ASP.NET</h1>
<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
<p>Learn more »</p>
</div>
<div class="row">
<div id="ajax-test"></div>
#using (Ajax.BeginForm("Test", new AjaxOptions()
{
UpdateTargetId = "ajax-test",
InsertionMode = InsertionMode.Replace
}))
{
<input type="submit" />
}
</div>
I've added a new action to HomeController:
public ActionResult Test()
{
return PartialView("Test");
}
A new view Home\Test.cshtml:
Hello world
And, crucially, I've added a reference to the required JavaScript files to _Layout.cshtml (moving them to the top of the page doesn't help).
...
#Scripts.Render("~/bundles/jquery")
#Scripts.Render("~/bundles/jqueryval")
#Scripts.Render("~/bundles/bootstrap")
#RenderSection("scripts", required: false)
</body>
</html>
I've verified the jqueryval bundle renders in the debug mode as:
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>
These entries were already present in web.config file:
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
I would expect that when I press Submit, the div will be populated with 'Hello world'. Instead, the whole page is replaced with 'Hello world' and the browser is redirected to /Home/Test. No errors reported in developer tools.
What element of the puzzle is missing? I know similar questions have been asked on StackOverflow before but the usual answer was to include these JavaScript files, which I did. Above are all the changes I've done to the template project so I can't see what I could break.

I've struggled with it for hours and managed to find the solution 5min after posting on StackOverflow. Typical.
I had to install a NuGet package Microsoft.jQuery.Unobrusive.Ajax, which is not installed by default, and add a reference to jquery.unobtrusive-ajax.js to the page. I thought it has been merged in into jquery.validate.unobtrusive.js or something but no.

Related

ckeditor toolbar doesn't show in asp.net masterpage scenario

I have an asp.net site, .net 4 framework. I'm trying to get the ckeditor up and running. Sorry, I'm a bit new to the ckeditor. There is a quick start guide here that shows you how to implement:
http://docs.ckeditor.com/#!/guide/dev_installation
I originally thought the editor wasn't showing the toolbar. However, after further debug, I believe the ckeditor isn't showing at all, and in fact, the textarea is still all that is showing.
I'm using the same code as on the example in the website. I've reposted that here:
<textarea name="editor1" id="editor1" rows="10" cols="80">
This is my textarea to be replaced with CKEditor.
</textarea>
<script>
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace('editor1');
</script>
I've included the script ckeditor.js script this way:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="DefectEntry3.aspx.cs" Inherits="DefectWriter.DefectEntry3" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script src="App_Data/ckeditor/ckeditor.js"></script>
I'm sure I'm making a simple mistake. Any help is appreciated.
Thanks!
Bob
I had the wrong path in the script source. Once I got the right path all is well.

using ckeditor does not work: when I click the path, it isn't going to the related file

I want to use ckeditor in a web page created in spring mvc 3.1. It is maven project.
I downloaded required files from http://ckeditor.com/download. I added taglib
<%# taglib uri="http://ckeditor.com" prefix="ckeditor" %>
on the head section.
In form, I wrote the code below. path="aciklama" is the property of my class. I want to bind data retrieved from ckeditor.
form method="post" modelAttribute="my class name">
.......
.....
<form:textarea cols="80" id="editor1" name="editor1" rows="10" path="aciklama"></form:textarea>
</form>
<ckeditor:replace replace="editor1" basePath="/ckeditor/" />
</body>
I also added these scripts, but it did not work:
<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/ckeditor/adapters/jquery.js"></script>
When I click the path, it isn't going to the related file. My ckeditor folder is under webpages. When I pass through files tab, It is shown under the webapp folder.
You can use this link for the reference
May be you have path problem i.e it is unable to find your ckeditor.js

my ckeditor is not loading the toolbar

I tried to install ckeditor in php but no result :S.
i have uploaded ckeditor file into the root of the site and i have a editor.html file where i have this code:
<html>
<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
<form method="post">
<p>
My Editor:<br />
<textarea id="editor1" name="editor1"><p>Initial value.</p></textarea>
<script type="text/javascript">
CKEDITOR.replace( 'editor1' );
</script>
</p>
<p>
<input type="submit" />
</p>
</form>
when i open the page it doesnt show the toolbar except a simple textarea.
Does any of you knows what I am actually missing here?
I don't know if this was your case, but in case it helps anyone else in the future...
I was adding CKEditor to my project and the toolbar wasn't showing for me either. I could tell the javascript file was loaded (and css files). There were no javascript errors either.
Eventually I narrowed it down to a conflict between a jquery plugin (jquery.stylish-select) and CKEditor. When I removed the plugin, the toolbar showed up perfectly.
Maybe you can try this:
CKEDITOR.replace('editor1', {width: 1050, height: 500, uiColor: '#e1e1e1'});
that means, you change the size....
So, can be, that it is better to use this CODE

ASP.MVC3 is client side validation enabled by default?

In my Layout page, i have the following links to the validation Javascript files,
<script src="#Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"> </script>
<script src="#Url.Content("~/Scripts/jquery.validate.min.js")"type="text/javascript"> </script>
<script src="#Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"type="text/javascript"></script>
My entities are decorated with validation attributes like
[Required(ErrorMessage ="Please enter a customer name")]
public string CustomerName { get; set; }
Then in my view i have validation messages specified after the update fields like so
<div class="label-for">#Html.LabelFor(model => model.CustomerName)</div>
<div class="editor">#Html.EditorFor(model => model.CustomerName)</div>
#Html.ValidationMessageFor(model => model.CustomerName)
The validation is working however its not on the client side, the way i understand this is that error messages should be displayed when one of the fields is left blank afer tabbing to another field, is there anything else required to get client side validation working?
IIRC there were some incompatibilities between jquery and jquery.validate versions. You seem to be using an old version of jquery 1.4.4. Try updating with the latest. For example install the ASP.NET MVC 3 Tools Update and create a new ASP.NET MVC project in Visual Studio which will get you the proper versions of the following scripts: jquery, jquery.validate and jquery.validate.unobtrusive.
May be this work: Make sure that in your web.config file, you set "ClientValidationEnabled" to "True"
<appSettings>
<add key="ClientValidationEnabled" value="true"/>
</appSettings>
NOTE: In MVC3 web project, there were two web.config files one under "View" folder another under root web project. make sure that the one in the root does not override the other.
jQuery validation has nothing to do with your validation mechanism. Maybe Microsoft.Ajax.Validation should be the responsible. But to use jquery.validation, you should write code. That's all. It doesn't do anything out of the box.

How do I place a magento autocomplete mini search box outside the magento installation?

I would like to put a magento mini search box in my main website, so that when a search is made, it redirects to the magento search results page. This global search is in the header and helps to find products fast on my Codeigniter main site. I was able to achieve part of this, by placing the following code:
<form method="get" action="http://pathtomagento/catalogsearch/result/" id="search_mini_form">
<div class="form-search">
<label for="search">Buscar:</label>
<input type="text" class="input-text" value="" name="q" id="search" autocomplete="off">
<button class="button" title="Buscar" type="submit"><span><span>Buscar</span></span></button>
<div class="search-autocomplete" id="search_autocomplete" style="display: none;"></div>
<script type="text/javascript">
//<![CDATA[
var searchForm = new Varien.searchForm('search_mini_form', 'search', 'Buscar en el catálogo...');
searchForm.initAutocomplete('http://pathtomagento/catalogsearch/ajax/suggest/', 'search_autocomplete');
//]]>
</script>
</div>
The autocomplete function of the search box doesn't work, which is a main issue for me since it's a really useful feature. My main website is full of jQuery, and I know Magento uses prototype. So I managed to include the following scripts that seem to be required by the autocomplete Magento search box:
<script type="text/javascript" src="pathtomagento/js/prototype/prototype.js"></script>
<script type="text/javascript" src="pathtomagento/js/varien/js.js"></script>
Still no luck! I don't get any Console errors in Firebug, but I don't get any AJAX or autocomplete response either. Does anyone know what I could be missing?
Your magento installation has to be on the same server because you can't make crossdomain AJAX requests. Maybe that is the problem in your case?

Resources