C# - ModelBinder With Multiple Selection And Complex Objects?

Feb 22, 2010

I'm trying to bind the selections in a multiple selection SELECT, to an IList input in the controller.

<select name="users" multiple="multiple">
<option>John</option>
<option>Mary</option>

[code]...

View 2 Replies


Similar Messages:

MVC :: Creating Multiple Complex Objects With A Webform?

Mar 3, 2010

I have a form which I use to create an issue. WHen you post the form, the form elements are that of a custom DTO. The DTO is then used on my POST method to create the new entity. That all works fine.

However, I want to add the functionality to add multiple issues at the same time from the same view. In effect, the user would click something like 'Report Additional Problem', and an extra set of form fields would appear (I will like use jquery for this, which I don't have an issue with). However, even with just leaving one set of form fields, the user should still be able to create just one issue. But if I habve my post method take a list or array of my DTO, it doesn't work.

Here is the post method before editing:

[Code]....

What I want to do is for this to take an array or list of NewIssueDto. I would then loop through each one in the list and create a new issue from it.

View 3 Replies

Passing Complex Objects To Javascript Via IScriptControl?

Mar 24, 2010

I'm playing around with a asp.net page that's using the IScriptControl interface to pass data from the code-behind to the custom javascript object running on the browser.I'm passing a number of properties via IScriptControl.GetScriptDescriptors(), and they're all working fine, except for one.That one is a class derived from System.Collections.Generic.Dictionary<>. And even that one has been working for me, so long as the elements in the collection were scalars - ints, doubles, and strings. But when I tried to pass a member of a class, it showed up as a null object in the javascript. The class in question is marked [Serializable]. I changed it to a struct, and got the same behavior.It looks as if the serializer used in IScriptControl does a shallow copy.

View 2 Replies

Use ObjectDataSource With Complex Objects And FormView Control?

Dec 30, 2010

I have a complex object. For example a SCHOOL object that contains a collection of PERSON object. How can I use the ObjectDataSource control with a FormView and flatten the complex object? An example display would be to display the school name and comma separate the students on the page. Is this possible?

public string Id
{
get { return m_id; }

[code]...

View 1 Replies

C# - How To Bind A DataTable With Complex Data Objects To A GridView

Jan 31, 2011

My DataTable is programatically generated, and contains objects of type JobInstance in the cells.

[Code]....

When I bind this DataTable to an ASP GridView, it only displays the first column. But if I remove the "typeof(Job)" when creating the column (the line with // !!!), the GridView displays all the columns by showing the result of JobInstance.ToString() in the cells. However, I have no access to the underlying JobInstance object, only the string values that are being displayed.

I need access to the JobInstance object when displaying the GridView (for example in the OnRowDataBound), because I want to access the fields inside JobInstance for each cell to determine formatting options, and add other links in each cell.

View 1 Replies

Use FormView In Order To Insert Complex Entity Framework Objects?

Jun 11, 2010

I'm trying to use formview in order to do insert of a new entity object (called Customer) Customer has a reference to another entity called Address. How can I fill both of them in the same formview?

View 1 Replies

DataSource Controls :: LINQ Mapping To Complex Business Objects?

Feb 5, 2010

I have two business objects mapped via LINQ to tables. One of the objects contains an instance of the other object and share a key as an identifier.I want to retrieve Class A and within class A all of Class B's values as well. What I am doing is this:

[Code]....

[Code]....

This seems a little clunky, as in slow. Is there a better way to get the Class B (User) information without making a query every time?

View 4 Replies

Entity Framework - Collection Of Complex Child Objects In MVC 3 Application?

Feb 20, 2011

I want to be able to update a model and all its collections of child objects in the same view. I have been referred to these examples: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx and http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/ .

For example, I have an object Consultant, that has a collection of "WorkExperiences". All this is in an Entity Framework model. In the view, the simple properties of the Consultant object is no problem, but the collection I cannot get a textbox to show up for. I tried following the examples in the links above, but it doesn't work. The problem is, in those examples the model is just a list (not an object with a child list property). And also, the model again is an EF model. And for some reason that doesn't seem to work as in those examples.

[Code]....

This stuff with the EditorTemplate works fine in Phil Haack's sample project, which I downloaded to try, but here, with the EF model or whatever the problem is, I don't get any textbox at all. The table in the view is just there as a test, because in the table I do get the rows for WorkExperiences, whether I add an empty WorkExperience object or fill out its properties doesn't matter, the rows show up for each object. But again, no textbox...

View 2 Replies

AJAX :: Sending Complex Objects From JavaScript (client) To C# (server)?

Mar 26, 2010

I have this object in my server side:

[Code]....

Now I do this on the client side, to send a typed object to the server:

[Code]....

and actually it works. The problem is that I cannot find the way to stablish this property: "public ThingDetails[] details;"

View 7 Replies

C# - Best Way To Edit And Update Complex Viewmodel Objects Using Mvc2 And Entity Framework?

Apr 2, 2010

I have a table in my database with a one to many relationship to another table, which has a relationship to a third table:

[Code].....

This seems to work fine. My question to you good folks: Is there a correct way to do this? I tried following the making a custom model binder per the blog link I posted above but it didn't work (there was an issue with reflection, the code expected certain properties to exist) and I needed to get something going ASAP. PS - I tried to cleanup the code to hide specific information, so beware I may have hosed something up.

View 1 Replies

AJAX :: Adding The 'multiple' Attribute To The Final Dropdown List And It Allows The Selection Of Multiple Items?

Mar 16, 2011

I am using the cascading dropdownlist controls from the Ajax toolkit. I have everything working perfectly and all of my select changes work. I have 3 related select boxes that all work great for single item select. What I need is for my last dropdownlist to allow for the selection of multiple items. I have tried adding the 'multiple' attribute to the final dropdown list and it allows the selection of multiple items but I cannot get the items when I post back, just a single item.

View 7 Replies

VS 2005 - List Box Will Not Allow Multiple Selection Even When Property Is Set To Multiple

Oct 24, 2012

I have a list box that I want to allow the users to select up to 4 items from. I set the selection property to multiple, but for the life of me it won't allow multiple selection. If I pre-select 4 items, they show up as all selected when the page loads, but as soon as I select another, it clears all of them and then only allows one at a time. if I check the source code for the page, the property is set to multiple (see below).

HTML Code:
<td colspan="2" style="height: 28px">
<select size="4" name="MonthsListBox" multiple="multiple" id="MonthsListBox">
<option value="Jan">Jan</option>
<option value="Feb">Feb</option>
<option value="Mar">Mar</option>
<option value="Apr">Apr</option>
<option value="May">May</option>
<option value="June">June</option>

</select></td>

View 4 Replies

Returning Complex Types (multiple Lists) To Client Side Using Jquery.ajax?

Feb 8, 2011

I'm designing a page which makes an ajax call (via jQuery.ajax) to a page method on the server side.On the server side, I have two classes: Agent and Channel.

In the page method, I'd like to return a List<Agent> and a List<Channel> to the client side. How can I return two lists to client side? should wrap them up in one class like:

[code]....

View 4 Replies

How To Use Multiple Session Objects

Jul 23, 2010

i want to use multiple session variables for single session i know how to use for multiple session variables i dont know

View 9 Replies

MVC :: Updating Multiple Objects In A View?

Jan 25, 2010

I have a view that is based on a view model. This model has a single property called Entity, of type ServiceProvider, which is a Linq2SQL object. This object has relationships to 2 other objects Address and ServiceProviderGroup. In a HTML view I have textboxes that allow the properties of the Entity property to be changed and also the properties of the Address object related to it.

E.g: ViewModel.Entity.Code, ViewModel.Entity.Name, ViewModel.Entity.Address.City, etc, etc.

There is also a selectlist that will allow the Entity.GroupId (int) property to be changed. This defines a relationship to the ServiceProviderGroup class which is also accessible via a Group propery. (standard linq2sql back references)

The Edit[Post] method accepts an instance of this view model and all properties (on the Entity, Entity.Address properties) are set as expected. I then lookup the original object in the database and I also bring back the original address and group data.

E.G: entity => entity.Code == viewModel.Code && entity.Address.Id == viewModel.Address.Id && entity.Group.Id == viewModel.Entity.GroupId (I'm not looking at the code, but it's something similar to this)

Either way the original Entity, Entity.Address, etc, come back from the database. I then apply the changes from the view model to the original object using UpdateModel and everything is updated as expected. But, if I try to change Entity.GroupId, i.e. change the relationship on the entity to another ServiceGroupProvider object, I get an exception in the generated code of the ServiceProvider object.

This happens in the GroupId property of the ServiceProvider class (viewModel.Entity). When it reaches the line if(!this.HasLoadedOrAssignedValue) it enters the "if" statement and throws an exception. When the data is first read from the database it skips this part. But, when UpdateModel attempts to apply the new Entity.GroupId value it throws the exception.

View 2 Replies

ASP MVC Elegant UI And ModelBinder Authorization?

Apr 29, 2010

We know that authorization's stuff is a cross cutting concern, and we do anything we could to avoid merge business logic in our views. But I still not find an elegant way to filter UI components (e.g. widgets, form elements, tables, etc) using the current user roles without contaminate the view with business logic. same applies for model binding.

Example
Form: Product Creation
Fields:
Name
Price
Discount
Roles:
Role Administrator

Is allowed to see and modify the Name field
Is allowed to see and modify the Price field
Is allowed to see and modify the Discount

Role Administrator assistant

Is allowed to see and modify the Name
Is allowed to see and modify the Price

Fields shown in each role are different, also model binding needs to ignore the discount field for 'Administrator assistant' role.

View 3 Replies

MVC :: ModelBinder Not Binding For Sub-object?

Jun 7, 2010

I have a class:

[Code]....

Then another class, for ProjectCustomer:

[Code]....

My view is the same as any standard auto-created view, with properties set using the likes of:

[Code]....

In my edit page, for editing the fields for these classes, everything works fine, the model binder works, and validation works. In my create page, only the Project class properties get set and the ProjectCustomer properties remain null. I've tried everything I can think of from manually instantiating a new ProjectCustomer before calling TryUpdate model, to letting MVC handle the lot by including the class as a paramater for the action. The values are being passed just fine, as I've tried a FormCollection too and in the debugger the FormCollection contains all the correct fields (i.e. Customer.Name etc.) yet no matter what the ModelBinder just wont attach the inputs to the Customer object inside the Project object, but will only not do this on the Create action, and does it fine for the Edit action even though the code is almost entirely identical.

why the ModelBinder is just refusing to bind for the Create action and no other? What steps can I perform to debug the ModelBinder when it's not working properly like this?

I've tried every combination of things I can think of under the sun, and simply can't understand why it works for one action, but not for another, especially when the code I've used is fairly basic. I'll note that these classes were intended as MetaData classes hence their pointless seeming simplicity, but as part of trying to track down the problem I've stripped them to the bare bones setup above, and still no luck.

Under what circumstances does the ModelBinder decide not to fill the properties of a sub-object?

View 2 Replies

C# - Is It Possible To Map Multiple DTO Objects To A Single ViewModel Using Automapper

Jan 24, 2010

I was wondering if it is possible to map multiple DTO objects to a single ViewModel object using Automapper?

Essentially, I have multiple DTO objects and would like to display information from each on a single screen in ASP.NET MVC 2.0. To do so I would like to flatten the DTO objects (or parts of them...) into the Viewmodel and pass said viewmodel to the view. If I had one DTO this would be easy, but I've never seen it being done with multiple. Obviously there are a number of roundabout ways to do this (outside of automapper), but this is the approach that I would like to take if possible.

View 1 Replies

MVC :: ModelBinder For Dependency Injection On ViewModels?

Jan 25, 2011

This project is pretty far away and I'm not in the position to go make changes all over the place (If I could, deleting the lot would be what I'd do!)

I want to create a modelbinder that would resolve any dependencies my View Models might have (using StructureMap).

It should not require me to implement a specific interface (so many developers, so many interfaces..I rather keep things clean) and hopefully not require one to go register each model binder individually (Now I'm asking too much,taking the first requirment
in consideration).

Probably will get it right tonight, but figured I'd ask.

View 3 Replies

MVC :: EditorTemplates - Split And Join - Use ModelBinder

Mar 29, 2010

I'm starting with EditorTemplates and I have this situation: I have and fild int that represents and phone number. In EditorTemplate I'll separate it in 2 textbox. But How can I join (concatenate) it in my action? If possible, I want to still use ModelBinder.

View 1 Replies

MVC :: Pattern For EF 4.0 CRUD / Transactions When Updating Multiple Objects?

Nov 17, 2010

I am looking for an accepted pattern for using MVC 2 and EF. Especially I am interested on how to implement updates. Where should the ObjectContext be created, where should the queries be, how to pass a model object from the controller and have it persisted with minimum robust code. I also want to be able to use transactions when updating multiple objects.

I used Linq in an asp.net application (code behind model). With EF I was hearing it was much more n-tier friendly, but I don't find it any different, rather than people talking about POCO which to me, all it means is satisfying the desire of those that want to have control of every piece of code being created.

View 6 Replies

MVC :: Handle Strongly Typed Views If Have Multiple Objects/models?

Mar 16, 2011

<p>Hi</p> <p>I'm a newbie in MVC but a veteran web forms developer. I really like the idea of strongly typed views but what if I have multiple objects to pass to my razor view. Would I then NOT use strongly typed views and just use the ViewBag?</p>

View 3 Replies

How To Handle Multiple Selection ListBox

May 14, 2010

In my aspx registration page i have more then 6 item available in my list box, I am allowing multiple selection on it..I am not sure about how many items i will select each and every time. then how i have to store it into dataset and how to pass it as a mysql paramter...

View 1 Replies

Using LIstbox Whith Multiple Selection?

Jan 3, 2011

I am using LIstbox whith Multiple Selection and wanted to save this value in one columns. I have selected employee name now i wanted to save this detail like A,B,X,D..

View 2 Replies

MVC :: Read Values From A Multiple Selection Dropdownlist

Jun 3, 2010

I have two ListBox in my ascx file, I fill them with some data (no problem here), I make them multiple and increase the size, below is my code.

[Code]....

I use some jQuery code to exchange element between them (Here too, no problem). My problem begin when I post my form, I'm unable to get the data from the DropDownList with attribute multiple or size. I tried in my controler to add a FormCollection parameter, I can see every element in my form except those select tag with more options than id and name. I tested to put a manual select tag in my code with only an id and a name then add size and multiple attribute, when there is only id and name I can get the value but when there are more I can't get my select tag in the FormCollection

Also I need to get all the value in the ListBoxand not only the ones who were selected. I have been searching answer for 2 fays now... Without success, I only find resource on how to show ListBoxbut not how to get values from them in mvc web site and I don't find any resources who talk about multiple selection ListBox, I think I'm a bad searcher but....

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved