Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
JQGrid, MVC3 and FluentNhibernate: search by text, not by key
06/12/2011
15:47
Avatar
Festus
Member
Members
Forum Posts: 3
Member Since:
06/12/2011
sp_UserOfflineSmall Offline

I am trying to implement an "as shipped" JQGrid search on a referenced field. I am having trouble displaying the text of the referenced Status model, as well as issues with the search not returning any results. Here are the models, map, viewmodel, controller, and view (as modeled after Trirand's demos):

Models:

public class Person { public virtual int Id { get; set; } public virtual int Name{ get; set; } public virtual Status { get; set; } } public class Status { public virtual int Id { get; set; } public virtual int Text{ get; set; } }

Map:

public class PersonMap : ClassMap<Person> { public PersonMap() { Id(t => t.Id); Map(t => t.Name); References(t => t.Status, "StatusID); } }

ViewModel:

public class PersonViewModel { public JQGrid PersonGrid { get; set; } int Id { get; set; } public virtual Status { get; set; } public string Name { get; set; } public PersonViewModel() { PersonGrid = new JQGrid { Columns = new List<JQGridColumn>() { new JQGridColumn { DataField = "Id", DataType = typeof(UInt32), HeaderText = "Id", PrimaryKey = true, Searchable = true, }, new JQGridColumn { DataField = "Status", HeaderText = "Status", DataType = typeof(Status), Searchable = true, }, new JQGridColumn { DataField = "Name", DataType = typeof(string), Searchable = true, } }, }; PersonGrid.ToolBarSettings.ShowSearchToolBar = true; } }

Controller:

public ActionResult Search() { var model = new PersonViewModel(); SetUpGrid(model); return View(model); } public void SetUpGrid(PersonViewModel model) { var PersonGrid = model.PersonGrid; PersonGrid.ID = "PersonGrid"; PersonGrid.DataUrl = Url.Action("PersonDataRequested"); } public JsonResult PersonDataRequested() { var model = new PersonViewModel(); JQGridState gridState = model.PersonGrid.GetState(true); Session["gridState"] = gridState; return model.PersonGrid.DataBind(_session.Query<Person>()); }

View:

@using Trirand.Web.Mvc @model ....PersonViewModel ...standard script/header stuff... <body> @Html.Trirand().JQGrid(Model.PersonGrid, "PersonGrid") </body>

The result I'm getting is that "Castle.Proxies.StatusProxy" is being displayed in the status column for each person in the grid, and no search by status (neither Id nor Text value) returns any results. The searches by the Person fields (Id and Name) work just fine.

06/12/2011
17:46
Avatar
Festus
Member
Members
Forum Posts: 3
Member Since:
06/12/2011
sp_UserOfflineSmall Offline

Ok. Wow. Really sorry about the formatting above. It is better formatted at

http://stackoverflow.com/quest.....bsp;though I don't think that is the

best forum for working with JQGrid.

09/12/2011
18:43
Avatar
Festus
Member
Members
Forum Posts: 3
Member Since:
06/12/2011
sp_UserOfflineSmall Offline

I've resolved the display issue by overriding the ToString() method for Status. As for the search issue, this is

what I've discovered:

What is being returned in both cases is a JSonResult. However, when searched by Status, the query itself

returns the expected results, but when the grid.DataBind executes, the JSonResult.Data member becomes

an Object rather than a JSonResponse. Looking at the query results, I cannot see any difference in types or

structure (or even the data), and hence no reason for the lack of convertion from object to JSonResponse.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
42 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information