A public action method 'ABC' was not found on controller xyz - asp.net-mvc

Background:
I'm doing some changes in already implemented project, Which uses MVC, Kendo Grid.And there is onePost action method called EmployeeSearchByName which takes one string parameter 'Name'.Kendo Grid's pages size is 10 records per page, when I search someones name control properly goes to that action and it fetches the employee according name and shows it in kendo grid but when I click on next page in kendo then I get the error 'A public action method 'EmployeeSearchByName ' was not found on controller xyz'.
Code Of View:
#model Silicus.Finder.Web.ViewModel.EmployeesViewModel
#using Kendo.Mvc.UI;
#using Silicus.Finder.Models.DataObjects;
<link href="~/Content/css/FinderStyle.css" rel="stylesheet" />
#{
ViewBag.Title = "Employees List";
var message = TempData["AlertMessage"] ?? string.Empty;
var importMessage = Session["ImportEmployee"] ?? string.Empty;
Session["ImportEmployee"] = string.Empty;
}
<link href="~/Content/MyKendoStyle.css" rel="stylesheet" />
<link href="~/Content/css/FinderStyle.css" rel="stylesheet" />
<div class="container-fluid" style="padding-right: 0px;padding-left: 0px;">
<div id="modal-container" class="k-popup" tabindex="-1" role="dialog" style="border-style: hidden;margin-top:-100px">
<div class="modal-content" style=" position:fixed !important;z-index:auto;width:97%;">
</div>
</div>
</div>
<div id="adv" class="container-fluid" style="margin-left: 3%;">
<div class="ContainerPanel">
<div>
<span style="color:black; font-weight: bold;">Advanced Search</span>
<div class="header1 pull-right">
<img src="~/Images/Project/down-arrow.png" style="height:20px; margin-top: -3px;" />
</div>
<div class="content">
<br />
#using (Html.BeginForm("GetEmployeesByCriteria", "Employee", FormMethod.Post))
{
var model = Model.SearchCriteria;
var i = 0;
if (i == 0)
{
#Html.EditorFor(modelItem => model, new { htmlAttributes = new { #class = "form-control" } });
++i;
}
}
</div>
</div>
</div>
</div>
<div id="Grid" class="container-fluid" style="margin: 0.5% 3% 0.5% 3%;">
#(Html.Kendo().Grid((IEnumerable<Silicus.Finder.Web.ViewModel.EmployeesListViewModel>)Model.Employees)
.Name("employeeListGrid")
.Columns(columns =>
{
columns.Bound(employee => employee.FullName).Template(#<label>
#Html.ActionLink(item.FullName, "Details", "Employee", new { id = item.EmployeeCode }, new { #class = "modal-link" })
</label>
);
columns.Bound(employee => employee.EmployeeCode).Title("Employee Code");
columns.Bound(employee => employee.Title);
columns.Bound(employee => employee.HighestQualification).Sortable(false);
columns.Bound(employee => employee.EmployeeType).Sortable(false);
columns.Bound(employee => employee.TotalExperienceInMonths);
columns.Bound(employee => employee.SilicusExperienceInMonths).Sortable(false);
})
.Scrollable(scr => scr.Height(300))
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.Sortable(sortable => sortable.AllowUnsort(false))
)
</div>
#Scripts.Render("~/bundles/jquery")
<script>
//Details Modal Popup
$(function () {
$('body').on('click', '.modal-link', function (e) {
e.preventDefault();
$(this).attr('data-target', '#modal-container');
$(this).attr('data-toggle', 'modal');
$('#Grid').toggle();
$('#adv').toggle();
});
$('body').on('click', '.modal-close-btn', function () {
$('#modal-container').modal('hide');
});
$('#modal-container').on('hidden.bs.modal', function () {
$(this).removeData('bs.modal');
});
$('#CancelModal').on('click', function () {
return false;
});
});
$(document).ready(function () {
$("#modal-container").hide();
$("#dialog-import-employee").hide();
});
$(window).load(function () {
$('#moduleHeaderTitleOnDashBoardImage').text("Employees");
$('#modal-container').hide();
});
$(".header1").click(function () {
$(".ContainerPanel").toggleClass("advance-width");
$header = $(this);
$content = $header.next();
$content.slideToggle(1, function () {
});
});
</script>
Question:How to resolve this ?

Kendo grid sends additional parameters which are used for its sorting & filtering.
Try to rewrite your action method like this:
public JsonResult GetIndexContent([DataSourceRequest]DataSourceRequest request, SearchCriteriaViewModel searchCriteria)
{
// your logic ... + return json
}
What we did additionally was telling the GridBuilder which Read method it should use. You even have the possibility to add searchCriteria as parameters;
.DataSource(datasource => datasource
.Ajax()
.Model(model => model.Id("Id"))
.Read(read => read.Action("GetIndexContent", "YourControllerName").Data(fetchSearchCriteriaMethodName))
.PageSize(10)
);
The JavaScript function 'fetchSearchCriteriaMethodName' should just return your search criteria as a JSON object.

Related

After calling view by form post method view design is changed in MVC

I am getting one issue in MVC project that when I load the page at that time view design is perfect but after the click event time when I called the same view at that time it changed the design.
I used one partial view, one view and one controller.
Now when call the index event at load event time the theme of website showing perfect. Here is the image:
Here is my controller code of index event:
public ActionResult Index()
{
try
{
var getYear = db.yearMaster.OrderBy(y => y.Year).ToList();
SelectList yearList = new SelectList(getYear, "YearID", "Year");
ViewBag.YearListName = yearList;
var getEvent = db.eventMaster.OrderBy(y => y.Event).ToList();
SelectList eventList = new SelectList(getEvent, "EventID", "Event");
ViewBag.EventListName = eventList;
var getBranch = db.branch.OrderBy(y => y.Branch).ToList();
SelectList branchList = new SelectList(getBranch, "BranchID", "Branch");
ViewBag.BranchListName = branchList;
var content = db.eventRegistration.Select(s => new
{
s.EventRegistrationID,
s.Image,
s.IsActive
}).Where(c => c.IsActive == true).Take(15).ToList();
List<EventRegistrationViewModel> contentModel = content.Select(item => new EventRegistrationViewModel()
{
EventRegistrationID = item.EventRegistrationID,
Image = item.Image,
IsActive = item.IsActive
}).ToList();
return View(contentModel);
}
catch (Exception ex)
{
return View();
}
}
Here is the view named index.cshtml:
#model IEnumerable<SchoolWebApplication.ViewModel.EventRegistrationViewModel>
#{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_PublicLayout.cshtml";
}
#*<script src="~/Scripts/jquery-1.8.2.min.js"></script>*#
<script src="~/js/jquery.mousewheel-3.0.6.pack.js"></script>
<script src="~/js/jquery.fancybox.js?v=2.1.3"></script>
<link href="~/Context/jquery.fancybox.css?v=2.1.2" rel="stylesheet" media="screen" />
<link href="~/js/jquery.fancybox.css" rel="stylesheet" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function ()
{
$("#ShowImage").fancybox({
helpers:
{
title:
{
type: 'float'
}
}
});
});
</script>
<style type="text/css">
.imgBox
{
width: 200px;
height: 200px;
opacity: 1.0;
filter: alpha(opacity=100);
}
.imgBox:hover
{
-moz-box-shadow: 0 0 10px #ccc;
-webkit-box-shadow: 0 0 10px #ccc;
box-shadow: 0 0 10px #ccc;
opacity: 0.4;
filter: alpha(opacity=40);
}
</style>
#using (Html.BeginForm("FilterImage", "Glimpses", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
#Html.AntiForgeryToken()
<script>
$(function () {
$("#YearList").change(function () {
$("#yearID").val($(this).val());
});
$("#eventList").change(function () {
$("#eventID").val($(this).val());
});
$("#branchList").change(function () {
$("#branchID").val($(this).val());
});
});
</script>
<fieldset>
<legend>
<div class="row">
<div class="col-sm-2" style="margin-left: 38px; width:149px">
#Html.DropDownList("YearList", ViewBag.YearListName as SelectList, "Select Year")
</div>
<div class="col-sm-2">
#Html.DropDownList("eventList", ViewBag.EventListName as SelectList, "Select Event")
</div>
<div class="col-sm-5">
#Html.DropDownList("branchList", ViewBag.BranchListName as SelectList, "Select Branch")
</div>
<div class="col-sm-1">
<input type="submit" value="Get Image" id="btn_searchimage" />
</div>
</div>
</legend>
</fieldset>
<div style="height:600px; margin-left: 25px;">
<div style="border-bottom:1px solid Red;"></div>
<div class="row-fluid">
<div class="span2">
<div class="item">
#foreach (var item in Model)
{
<script>
alert();
</script>
<div style=" margin:10px; float:left; height:200px; overflow:hidden; width:200px;">
<a id="ShowImage" class="fancybox-button" data-rel="fancybox-button"
href="#">
<div class="zoom">
<img src='/Glimpses/RetrieveEventImage/#item.EventRegistrationID' alt="No Image" class="imgBox"/>
<div class="zoom-icon"></div>
</div>
</a>
</div>
}
</div>
</div>
</div>
</div>
}
Now, up to this there is no problem but if I filter the data as seen in image and call the view, at that time the design is changed.
Here is the image of the changed image:
Here is the filterimage event code in the same controller:
public ActionResult FilterImage(EventRegistrationViewModel eventRegistrationViewModel, int yearList, int eventList, int branchList) //
{
try
{
var getYear = db.yearMaster.OrderBy(y => y.Year).ToList();
SelectList abc = new SelectList(getYear, "YearID", "Year");
ViewBag.YearListName = abc;
var getEvent = db.eventMaster.OrderBy(y => y.Event).ToList();
SelectList def = new SelectList(getEvent, "EventID", "Event");
ViewBag.EventListName = def;
var getBranch = db.branch.OrderBy(y => y.Branch).ToList();
SelectList ijk = new SelectList(getBranch, "BranchID", "Branch");
ViewBag.BranchListName = ijk;
var content = db.eventRegistration.Select(s => new
{
s.EventRegistrationID,
s.EventID,
s.Image,
s.IsActive,
s.YearID,
s.BranchID
}).Where(c => c.IsActive == true && c.YearID == yearList && c.BranchID == branchList && c.EventID == eventList).ToList();
List<EventRegistrationViewModel> contentModel = content.Select(item => new EventRegistrationViewModel()
{
EventRegistrationID = item.EventRegistrationID,
Image = item.Image,
IsActive = item.IsActive,
YearID = yearList,
BranchID = branchList
}).ToList();
return View("index",contentModel);
}
catch (Exception ex)
{
return View();
}
}
For me the problem is with this type of linking scripts and css. Try to resolve your url on server using this:
<%=ResolveUrl("~/path/file.js")
Like this:
<script src="<%=this.ResolveUrl("~/js/jquery.mousewheel-3.0.6.pack.js")%>"></script>

Gap between header and rest of calendar

I am having problem with rendering fullcalendar in my asp.net mvc application. Library I am using is Fullcalendar jquery.
As shown by the lower arrow in picture,blue event date range between times is actually between 12 am and 1 am, but in calendar event marked in blue exceeds 1 am. Why? It also seems that there is some kind of a gap as shown by the above arrow between header and the rest of calendar. See the picture_1.See the picture_2
Here is cshtml code:
model OrdinacijaS.Termin
#{
ViewBag.Title = "Create";
}
<h2>Create</h2>
#using (Html.BeginForm()) {
#Html.AntiForgeryToken()
#Html.ValidationSummary(true)
<fieldset>
<legend>Termin</legend>
<div class="editor-label">
#Html.LabelFor(model => model.Pocetak)
</div>
<div class="editor-field">
#Html.TextBoxFor(model => model.Pocetak, new { id = "textBoxPocetak" })
#Html.ValidationMessageFor(model => model.Pocetak)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.Kraj)
</div>
<div class="editor-field">
#Html.TextBoxFor(model => model.Kraj, new { id = "textBoxKraj" })
#Html.ValidationMessageFor(model => model.Kraj)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.Pacijent_PacijentId, "Pacijent")
</div>
<div class="editor-field">
#Html.DropDownList("Pacijent_PacijentId", String.Empty)
#Html.ValidationMessageFor(model => model.Pacijent_PacijentId)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.Zahvat_ZahvatId, "Zahvat")
</div>
<div class="editor-field">
#Html.DropDownList("Zahvat_ZahvatId", String.Empty)
#Html.ValidationMessageFor(model => model.Zahvat_ZahvatId)
</div>
<p>
<input type="submit" value="Create" id="submitButton" />
</p>
</fieldset>
}
<div>
#Html.ActionLink("Back to List", "Index")
</div>
<div id="calendar"></div>
#*<link href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.min.css" rel="stylesheet" />#
<link href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.print.css" rel="stylesheet" media="print" />*#
<link href='/Content/fullcalendar.css' rel='stylesheet' />
<link href='/Content/fullcalendar.print.css' rel='stylesheet' media='print' />
Here is javascript code:
#section Scripts {
#*#Scripts.Render("~/bundles/jqueryval")*#
#*<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js" rel="stylesheet"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.min.js" rel="stylesheet"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/locale/hr.js" rel="stylesheet"></script>*#
<script src='Scripts/jquery.min.js' rel="stylesheet"></script>
<script src='Scripts/moment.min.js' rel="stylesheet"></script>
<script src='Scripts/fullcalendar/fullcalendar.js' rel="stylesheet"></script>
<script>
$(document).ready(function(myevents){
var myevents = [];
$.ajax({
cache: false,
type: "GET",
asyc:false,
url: "/Termin/getTermin",
success: function (data) {
$.each(data, function (i, v) {
myevents.push({
title: v.Ime,
description: "some description",
start: moment(v.Pocetak),
end: v.Kraj != null ? moment(v.Kraj) : null,
color: "#378006",
allDay: false
});
})
alert(myevents.length);
GenerateCalendar(myevents);
},
error: function (error) {
alert(error);
}
})
})
GenerateCalendar();
function GenerateCalendar(myevents) {
$('#calendar').fullCalendar('destroy');
$('#calendar').fullCalendar({
defaultDate: new Date(),
defaultView: 'agendaWeek',
timeFormat: 'h(:mm)a',
header: {
left: 'prev, next, today',
center: 'title',
right: 'month, basicWeek, basicDay, agenda'
},
eventLimit: true,
eventColor: "#378006",
events: myevents,
selectable: true,
allDaySlot: false,
select: function(start, end, allDay) {
endtime = moment(end).format('YYYY/MM/DD hh:mm');
starttime = moment(start).format('YYYY/MM/DD hh:mm');
var mywhen = starttime + ' - ' + endtime;
$("#textBoxPocetak").val(starttime);
$("#textBoxKraj").val(endtime);
},
businessHours: {
dow: [1, 2, 3, 4],
start: '8:00am',
end: '4:00pm',
}
})
}
$("#submitButton").on('click', function () {
//var myEvent = [];
//myEvent.push({
// title: 'Long Event',
// start: '2017-08-08T08:30:00',
// end: '2017-08-08T09:30:00'
//});
//myEvent = {
// title: 'Long Event',
// start: '2017/08/08 08:30',
// end: '2017/08/08 09:30'
//};
//$('#calendar').fullCalendar('renderEvent', myEvent, 'stick');
//myEvent = {
// title: 'Long Event',
// start: $('#textBoxPocetak').val(),
// end: $('#textBoxKraj').val()
//};
//$('#calendar').fullCalendar('renderEvent',myEvent,true);
//$('#calendar').fullCalendar('renderEvent', {
// title: 'Long Event',
// start: '2017-08-08T08:30:00',
// end: '2017-08-08T09:30:00'
//}, true);
//$("#calendar").fullCalendar('addEventSource', myEvent);
//$('#calendar').fullCalendar('updateEvent', myEvent);
});
</script>
}
Here is css code:
<style>
.fc-sun{
color:#FFF;
background: red;
}
.fc-clear {
clear: none !important;
}
</style>
Sorry for delayed answer, but (I think) I found a solution. I implemented FullCalendar jquery using MVC 4 application in Visual Studio 2013. MVC4 doesn't come with included bootstrap.js dependency,like later versions of MVC (MVC5 for example). It seems that Full Calendar jquery is somehow connected or depended on bootstrap.js becasue the moment after I installed booststrap.js (via Nugget)and included it in my MVC4 procjet the problem solved.

JQuery Line is not Executing

I'm not sure why this JQuery line is not executing :
$('#Client').change(function ()...
My code is :
#model StockHoldings.Models.Investments
<head>
<script src="jquery-3.1.1.min.js"></script>
#*<script src="http://code.jquery.com/jquery-1.10.1.min.js" type='text/javascript'></script>*#
</head>
#using (Html.BeginForm())
{ #Html.DropDownList("Client", ViewData["client"] as SelectList, "Select Client", new { id = "Client_ID", style = "width: 150px;" })<br />
#*{ #Html.DropDownList("Fund", "Select Fund")};*#
<select id="Fund" name="Fund" , style="width: 150px;"></select><br />
<div class="form-group">
#Html.LabelFor(model => model.PurchaseDate, htmlAttributes: new { #class = "control-label col-md-2" })
<div class="col-md-10">
#Html.EditorFor(model => model.PurchaseDate, new { htmlAttributes = new { #class = "form-control" } })
#Html.ValidationMessageFor(model => model.PurchaseDate, "", new { #class = "text-danger" })
</div>
</div>
}
#Scripts.Render("~/bundles/jquery")
<script type="text/jscript">
$(document).ready(function () {
$('#Client').change(function ()
{
alert('here');
$.getJSON('#Url.Action("ClientInvestmentsSince2", "Reports")', { id: $(#Client).val() }, function (data)
//$.getJSON('#Url.Action("ClientInvestmentsSince2", "Reports")', { id:1 }, function (data)
{
var items = '<option>Select Fund</option>';
$.each(data, function (i, fund)
{
items += "<option value='" + fund.Value + "'>" + fund.Text + "</option>";
})
.fail(function (jqxhr, textStatus, errorMessage) { alert(errorMessage); });
//assign the result to the Fund selectlist
$('#Fund').html(items);
});
});
});
</script>
Your SELECT element's Id is Client_ID. But in your javascript code, you are binding the click event to an element with Id Client
Either change your jQuery selector to use the correct Id
$(function(){
$('#Client_ID').change(function (){
var clientId = $(this).val();
alert(clientId );
//use clientId for your ajax call
});
})
Or use the the name attribute for your jQuery selector.
$(function(){
$('SELECT[name="Client"]').change(function(){
var clientId = $(this).val();
alert(clientId );
//use clientId for your ajax call
});
})
This should work assuming you do not have any other script errors in your page which is preventing this js code to execute.

Facing issue while submitting Partial View using JQuery post

I have an Area like below.
Controller Class
public class AdminController : Controller
{
//
// GET: /Admin/Admin/
[HttpPost]
public ActionResult Index_partialPost(AdminModule model)
{
return PartialView("_PartialPage1", model);
}
[HttpGet]
public ActionResult Index_partial()
{
return PartialView("_PartialPage1");
}
[HttpGet]
public ActionResult Index()
{
AdminModule model = new AdminModule();
model.MyName = "My Name";
return View("Index", model);
}
}
View
#model _1.Areas.Admin.Models.AdminModule
#{
ViewBag.Title = "Index";
Layout = "~/Areas/Admin/Views/Shared/_LayoutPage1.cshtml";
}
<h2>
Index</h2>
<div id="myForm">
<p id="pid">
</p>
</div>
<input id="BTN" type="submit" value="Button" />
<script language="javascript" type="text/javascript">
$('#BTN').click(function(){
$('#pid').load("#Url.Action("Index_partial", "Admin")");
});
</script>
View
#model _1.Areas.Admin.Models.AdminModule
#{
ViewBag.Title = "Index";
Layout = "~/Areas/Admin/Views/Shared/_LayoutPage1.cshtml";
}
<h2>
Index</h2>
<script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript">
</script>
<div id="myForm">
<p id="pid">
</p>
</div>
<input id="BTN" type="submit" value="Button" />
<script language="javascript" type="text/javascript">
$('#BTN').click(function(){
$('#pid').load("#Url.Action("Index_partial", "Admin")");
});
</script>
Partial View
#model _1.Areas.Admin.Models.AdminModule
#using (Html.BeginForm())
{
#Html.LabelFor(i => i.MyName)
#Html.TextBoxFor(i => i.MyName)
#Html.ValidationMessageFor(i => i.MyName)
<p id="getDateTimeString">
</p>
<input type="submit" value="Click here" id="btn" />
}
<script language="javascript" type="text/javascript">
$('#btn').click(function () {
var url = '#Url.Action("Index_partialPost", "Admin")';
$.post(url, null, function (data) {
});
});
</script>
Issue is - When trying to post the partial view using jQuery-post not working and giving 404. It's working with Ajax using below mentioned code of Partial View
#model _1.Areas.Admin.Models.AdminModule
#using (Ajax.BeginForm("Index", "Admin",
new AjaxOptions { UpdateTargetId = "myForm", HttpMethod = "Post" }))
{
#Html.LabelFor(i => i.MyName)
#Html.TextBoxFor(i => i.MyName)
#Html.ValidationMessageFor(i => i.MyName)
<p id="getDateTimeString">
</p>
<input type="submit" value="Click here" id="btn" />
}
You should cancel the default action of the form by returning false from your click handler:
<script type="text/javascript">
$('#btn').click(function () {
var url = '#Url.Action("Index_partialPost", "Admin")';
$.post(url, null, function (data) {
});
return false;
});
</script>
If you don't do that, the form is submitted to the server and the browser redirects to the target url leaving you absolutely no time for your AJAX request to ever execute.
Notice that it is much better to subscribe to the .submit event of the form in order to perform the AJAX request instead of the .click event of the submit button. The reason for this is obvious: there are other means to submit a form than clicking on a submit button. For example pressing the Enter key while inside an input field. If this happens your AJAX will never execute.
So here's the correct way. Start by giving an unique id to your form:
#using (Html.BeginForm(null, null, FormMethod.Post, new { id = "myForm" }))
{
#Html.LabelFor(i => i.MyName)
#Html.TextBoxFor(i => i.MyName)
#Html.ValidationMessageFor(i => i.MyName)
<p id="getDateTimeString">
</p>
<input type="submit" value="Click here" id="btn" />
}
and then you could unobtrusively AJAXify this form:
<script type="text/javascript">
$('#myForm').submit(function () {
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function(result) {
}
});
return false;
});
</script>
I think you need to define the Area in the routeparameter where you do #Url.Action in your partial view:
$('#btn').click(function () {
var url = '#Url.Action("Index_partialPost", "Admin", new { area = "Admin"})';
$.post(url, null, function (data) {
});
});
Else it will be posted to your main (root) Area where you probably don't have a AdminController...
You can doublecheck the url in the JS your HTML source when the form is rendered, it sould read "/Admin/Admin/Index_partialPost" instead of just "/Admin/Index_partialPost"

Firefox "jQuery is not defined" error in asp.net mvc 3

I'm using asp.net mvc also using jQuery ui dialog, i'm showing a partialview in a jQuery dialog but Firefox give me an error on these two files below. I post an Ajax.BeginForm() to server. on first post it's working fine but on sencond post it destroys my dialog.
jquery.validate.min.js
jquery.validate.unobtrusive.min.js
Error : jQuery is not defined
I dont have this problem in IE, please help.
#model MvcSmkApplication.Models.LoginModel
<script src="#Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
#using (Ajax.BeginForm("AuthenticateUser", "Members", new AjaxOptions
{
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "LoginForm",
OnSuccess = "OnSuccess",
}))
{
<div id="LoginForm">
#Html.ValidationSummary(true)
<fieldset>
<legend></legend>
<div class="editor-label">
#Html.LabelFor(model => model.EmailAddress)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.EmailAddress)<br />
#Html.ValidationMessageFor(model => model.EmailAddress)
</div>
<div class="editor-label">
#Html.LabelFor(model => model.Password)
</div>
<div class="editor-field">
#Html.EditorFor(model => model.Password)<br />
#Html.ValidationMessageFor(model => model.Password)
</div>
#foreach (ModelState modelState in ViewData.ModelState.Values)
{
foreach (ModelError error in modelState.Errors)
{
<div style="color: Red;">#error.ErrorMessage</div>
}
}
<div style="float: right;">
<input type="submit" value="Login" class="buttonAsLink" />
</div>
</fieldset>
</div>
}
<script type="text/javascript">
function OnSuccess(e) {
if (e["success"] == "true") {
$("#dialog").dialog("close");
location.reload();
}
else {
//alert('error');
}
}
</script>
You might try referencing your scripts like this:
<script src="#Url.Content("~/Scripts/jquery.validate.min.js")"></script>
Here is the solution which I found it after 3 weeks research.
<script type="text/javascript">
function OnSuccess(e) {
if (e["success"] == "true") {
$("#dialog").dialog("close");
location.reload();
}
else {
$("#dialog").html(e);
return false;
}
}
</script>

Resources