Ich bin vor einem Problem, wenn http://www.jeasyui.com/tutorial/app/crud/index.htmlProbleme beim Schließen speichert jeasyui Dialogfeld Raster
tun Nachdem ich das neue Element gespeichert, habe ich erfolgreich die Datenbank aktualisieren, aber wenn die Javascript-Aufruf Saveuser-Funktion der zum Schließen Dialogfeld und das Raster aktualisieren, ich diesen Fehler immer bekam:
Uncaught SyntaxError: Unexpected token)
at HTMLFormElement.success (http://localhost:58137/scripts/scripteasyui.js:22:44)
at HTMLIFrameElement.cb (http://www.jeasyui.com/easyui/jquery.easyui.min.js:7707:14)
at HTMLIFrameElement.handle (http://code.jquery.com/jquery-1.6.min.js:16:32793)
at HTMLIFrameElement.k (http://code.jquery.com/jquery-1.6.min.js:16:29553)
ich MVC C# bin mit, hier ist mein Code:
Für den Kopf auf der Ansicht html
für die scripteasyui.js Datei:
var url;
function newBrand() {
$('#dlg').dialog('open').dialog('center').dialog('setTitle', 'New User');
$('#fm').form('clear');
url = 'SaveBrands';
}
function editBrand() {
var row = $('#dg').datagrid('getSelected');
if (row) {
$('#dlg').dialog('open').dialog('center').dialog('setTitle', 'Edit User');
$('#fm').form('load', row);
url = 'update_user.php?id=' + row.id;
}
}
function saveBrand() {
$('#fm').form('submit', {
url: url,
onSubmit: function() {
return $(this).form('validate');
},
success: function (result) {
var result = eval('(' + result + ')');
if (result.errorMsg) {
$.messager.show({
title: 'Error',
msg: result.errorMsg
});
} else {
$('#dlg').dialog('close'); // close the dialog
$('#dg').datagrid('reload'); // reload the user data
}
}
});
}
function destroyBrand() {
var row = $('#dg').datagrid('getSelected');
if (row) {
$.messager.confirm('Confirm', 'Are you sure you want to destroy this user?', function (r) {
if (r) {
$.post('destroy_user.php', { id: row.id }, function (result) {
if (result.success) {
$('#dg').datagrid('reload'); // reload the user data
} else {
$.messager.show({ // show error message
title: 'Error',
msg: result.errorMsg
});
}
}, 'json');
}
});
}
}
für die Methode speichern auf dem Controller
public void SaveBrands()
{
string brandid = Request.Form["brandid"];
string brandname = Request.Form["brandname"];
using (ItemsEntities db = new ItemsEntities())
{
db.Brands.Add(new Brand { BrandID = brandid, BrandName = brandname });
db.SaveChanges();
}
}
Für die Listendaten zeigt
public JsonResult ShowBrands(string sidx, string sort, int page, int rows)
{
sort = (sort == null) ? "" : sort;
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
using (ItemsEntities db = new ItemsEntities())
{
var brandqry = db.Brands.OrderBy(e => e.BrandID);
int RecCount = brandqry.Count();
var totalPages = (int)Math.Ceiling((float)RecCount/(float)rows);
var jsonData = new
{
total = totalPages,
page,
records = RecCount,
rows = brandqry.ToList(),
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
}