Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON returns raw serialised data to browser page instead of a grid and formatted HTML
    primarykey
    data
    text
    <p>My Data appears in IE like</p> <p>[{"UserId":1,"Surname":"Scccce","Forename":"John","Pax":"0777533303","Mobile":"07775803803","Email":"john803.......</p> <p>When I want the Javascript to fire and create a grid...</p> <p>My Controller Code is:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Mvc.Ajax; using Emas.Model; using Emas.Web.Models.Repositories; using Emas.Web.Models.FormViewModels; using Emas.Web.Helpers; using Emas.Web.Extentions; using System.Web.Script.Serialization; namespace Emas.Web.Controllers { [Emas.Web.Helpers.AuthorizeHelpers.EMASAuthorize] public class UserController : Controller { private EmasDataContext _db = new EmasDataContext(); private SecurityRepository _securityRepository = new SecurityRepository(); #region Index public ActionResult Index() { //if (!User.IsInRole("Active")) // return View("NotAuthorised"); if (!User.IsInRole("Admin")) // Only ADMIN users can setup user access and roles return View("NotAuthorised"); var allUsers = _securityRepository.FindAllUsers(); if (allUsers == null) return View("NotFound"); return View(allUsers); } public JsonResult IndexJSon() { //if (!User.IsInRole("Active")) // return View("NotAuthorised"); //var allUsers = _securityRepository.FindAllUsers(); //return this.Json(allUsers); var results = from user in _db.aspnet_Users select new { UserId = user.UserId, Surname = user.Surname, Forename = user.Forename, Pax = user.Pax, Mobile = user.Mobile, Email = user.Email, Active = user.Active, UserName = user.UserName }; return Json(results); } public JsonResult Index2() { var results = from user in _db.aspnet_Users select new { UserId = user.UserId, Surname = user.Surname, Forename = user.Forename, Pax = user.Pax, Mobile = user.Mobile, Email = user.Email, Active = user.Active, UserName = user.UserName }; return this.Json(results, "text/html"); } #endregion Index #region Details public ActionResult Details(int id) { aspnet_User user = _securityRepository.GetUser(id); if (user == null) return View("NotFound"); return View(new UserFormViewModel(user, this._securityRepository.FindAllRoles(), this._securityRepository.FindAllUsers())); } #endregion Details #region Delete [AcceptVerbs(HttpVerbs.Delete)] public void Delete(int id, string ConfirmButtons) { aspnet_User user = _securityRepository.GetUser(id); this._securityRepository.Delete(user); this._securityRepository.Save(User.Identity.Name); } #endregion Delete #region Create // GET: public ActionResult Create() { aspnet_User user = new aspnet_User(); return View(new UserFormViewModel(user, this._securityRepository.FindAllRoles(), this._securityRepository.FindAllUsers())); } // POST: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(aspnet_User user, string[] Roles) { if (user.UserName != null) user.LoweredUserName = user.UserName.ToLower(); //TODO dc - hardcoded for demo - fix user.ApplicationId = new Guid("311566ad-a279-4d0b-a883-89425bdc69e3"); _securityRepository.Add(user); if (Roles == null) { //ModelState.AddModelError("User In Roles", "You must select at least one Role for this user to be in."); //Code Removed during UAT, being in no Roles implies READ ONLY user } else { foreach (string role in Roles) { aspnet_UsersInRole userInRole = new aspnet_UsersInRole() { //RoleId = new Guid(role), GUID removed UserId = user.UserId }; user.aspnet_UsersInRoles.Add(userInRole); } } if (!ModelState.IsValid) return View(new UserFormViewModel(user, this._securityRepository.FindAllRoles(), this._securityRepository.FindAllUsers())); this._securityRepository.Save(User.Identity.Name); return RedirectToAction("Index", new { id = user.UserId }); } #endregion Create #region Edit // GET: public ActionResult Edit(int id) { aspnet_User user = _securityRepository.GetUser(id); if (user == null) return View("NotFound"); return View(new UserFormViewModel(user, this._securityRepository.FindAllRoles(),this._securityRepository.FindAllUsers())); } // POST: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(int id, string[] Roles) { aspnet_User user = _securityRepository.GetUser(id); _securityRepository.DeleteUserInRoles(user); if (Roles == null) { //ModelState.AddModelError("User In Roles", "You must select at least one Role for this user to be in."); //Code Removed during UAT, being in no Roles implies READ ONLY user } else { foreach (string role in Roles) { aspnet_UsersInRole userInRole = new aspnet_UsersInRole() { //RoleId = new Guid(role), UserId = user.UserId }; user.aspnet_UsersInRoles.Add(userInRole); } } TryUpdateModel(user); if (!ModelState.IsValid) return View(new UserFormViewModel(user, this._securityRepository.FindAllRoles(), this._securityRepository.FindAllUsers())); this._securityRepository.Save(User.Identity.Name); return RedirectToAction("Index"); } public ActionResult ReassignActions(int id) { aspnet_User user = _securityRepository.GetUser(id); if (user == null) return View("NotFound"); return View(new UserFormViewModel(user, this._securityRepository.FindAllRoles(), this._securityRepository.FindAllUsers())); } // POST: [AcceptVerbs(HttpVerbs.Post)] public ActionResult ReassignActions(int id, string[] Roles,Guid UserLoginId) { if (!User.IsInRole("Admin")) // If Admin user then block from EDITING return View("NotAuthorised"); aspnet_User user = _securityRepository.GetUser(id); //this._db.ReassignUserScheduledActions(user.UserId.ToString(), UserLoginId.ToString()); return View(new UserFormViewModel(user, this._securityRepository.FindAllRoles(), this._securityRepository.FindAllUsers())); } #endregion Edit } } </code></pre> <p>My index2.aspx is:</p> <pre><code>&lt;%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="application/json; charset=utf-8" /&gt; &lt;title&gt;My First Grid&lt;/title&gt; &lt;link type="text/css" href="~/Content/jQueryUI/css/jquery-ui-1.8.11.custom.css" rel="stylesheet" /&gt; &lt;link href="~/Content/jquery-1/css/ui.jqgrid.css" rel="stylesheet" type="text/css" /&gt; &lt;style type="text/css"&gt; html, body { margin: 0; padding: 0; font-size: 75%; } &lt;/style&gt; &lt;script src="~/Scripts/jquery-1.5.2.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="~/Content/jquery-1/js/grid.locale-en.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="~/Content/jquery-1/js/jquery.jqGrid.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;table id="list"&gt;&lt;/table&gt; &lt;div id="pager"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; &lt;script type="text/javascript"&gt; $(function() { alert(33); $("#list").jqGrid({ url: $("#AbsolutePath").val() + "/User.mvc/Index2", datatype: 'json', ajaxGridOptions: { contentType: 'application/json; charset=utf-8' }, mtype: 'GET', colNames: ['UserId', 'Surname', 'Forename', 'Pax', 'Mobile', 'Active', 'Email'], colModel: [ { name: 'UserId', index: 'UserId', width: 80, editable: true, editoptions: { size: 10} }, { name: 'Surname', index: 'Surname', width: 90, editable: true, editoptions: { size: 25} }, { name: 'Forename', index: 'Forename', width: 60, align: "right", editable: true, editoptions: { size: 10} }, { name: 'Pax', index: 'Pax', width: 60, align: "right", editable: true, editoptions: { size: 10} }, { name: 'Mobile', index: 'Mobile', width: 60, align: "right", editable: true, editoptions: { size: 10} }, { name: 'Active', index: 'Active', width: 55, align: 'center', editable: true, edittype: "checkbox", editoptions: { value: "Yes:No"} }, { name: 'Email', index: 'Email', width: 100, sortable: false, editable: true, edittype: "textarea", editoptions: { rows: "2", cols: "20"} } ], pager: '#pager', rowNum: 10, rowList: [10, 20, 30], sortname: 'Surname', sortorder: 'desc', viewrecords: true, caption: 'My first grid' }); }); &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload