2016-11-22 12 views
0

を閉じるとき、私は新しいアイテムを保存した後 http://www.jeasyui.com/tutorial/app/crud/index.html問題ダイアログボックスjeasyuiグリッド保存

を行うとき、私は成功し、データベースを更新してきた問題に直面していますが、JavaScript呼び出しsaveUser機能がクローズするときダイアログボックスとグリッドを更新し、私はいつもこのエラーを得た:

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) 

私はMVCのC#を使用しています、ここに私のコードは次のとおりです。

ビューHTML

のヘッドについてscripteasyui.jsため
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/default/easyui.css"> 
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/icon.css"> 
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/color.css"> 
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/demo/demo.css"> 
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script> 
<script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script> 
<script src="~/scripts/scripteasyui.js"></script> 

210ファイル:

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'); 
      } 
     }); 
    } 
} 

保存方法のためのコントローラ

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(); 
     } 

    } 

にリストデータ

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); 

      } 
     } 

答えて

0

を示すために、私は答えを見つけました私はjavascriptの結果パラメータの結果をjasonにシリアル化する必要があります

string jsondata = JsonConvert.SerializeObject(brandmdl); 
      return Json(jsondata); 
関連する問題