MVC :: ModelBinding (SelectListItem To Custom Type)

Apr 24, 2010

Perhaps should have posted this with my previous question, but now that I figured the problem, it might be better to create a new one.

My viewmodel is a custom type (say Person) and one of it's members another custom type (say "EmploymentStatus").

I got a list of "EmploymentStatuses" which I convert from IEnumerable<EmploymentStatus> to a SelectList

[Code]....

and I use this list in my View (Strongly typed using PersonModel)

[Code]....

All fine. The problem is that my controller expect a person object and when it does validation, it tell me that the employment status selection are not valid. Obviously because a EmploymentStatus object are expected whereas the View return a SelectListItem.

View 2 Replies


Similar Messages:

MVC :: How To Convert SelectListItem To Custom Type

Apr 23, 2010

Example: I create a custom type in my domain model (say a "Country" class with Id and Text fields)

A "Person" object have a property of the above type.

The Service class return a list of Countries (IEnumerable<Country> GetCountries();)

Now the ViewModel, derive from the "Person" object and have a member "Countries" which is IEnumerable<SelectListItem> Countries (It convert the Country collection from the service to a collection of SelectListItems.

I use the SelectLIst collection to populate my dropdown.

However when I submit the form, validation fail, obviously because the "Country" dropdown give a string value, while a Country object is expected.

So I need to cast this value from a string (using the "id" of the SelectListItem) to a Country object.

Where and how would be the right way to do this? (Another late night with me bing brain dead and probably overlooking the obvious).

View 4 Replies

MVC :: Modelbinding Differences Between Letting The Framework Do The Modelbinding To A Parameter

May 23, 2010

What is the difference, if any, between letting the framework do the modelbinding to a parameter:

[Code]....

vs. invoking the modelbindng manually/explicitly in the action method:

[Code]....

Is there any difference(s)? E.g., does the framework use the parameter name (m) during the modelbinding in the former method in some way that it might not do in the latter way?

View 2 Replies

MVC :: DropDownList Helper And SelectListItem Selected Property Being Ignored?

Jul 6, 2010

I am producing a List(Of SelectListItem) from my database and passing this to a DropDownList Html Helper method on my View via the controller.This works ok but I seem to have found a bug or issue where the DropDownList ignores the Selected property of the SelectListItem objects in the list.I have a provider class in my model which will read the database, create the List(Of SelectListItem) and then depending on whether or not the user is associated with one of the options, I will set the Selected property to True for that item.

code]...

View 16 Replies

Custom Server Controls :: Using The Generic Type 'System.Collections.Generic.IEnumerable' Requires '1' Type Arguments

Nov 25, 2010

I'm trying to create a control out of a class I found, and one of the overridden functions is the following:

protected override void PerformDataBinding(IEnumerable data)

However, when I try to build the control I'm getting the error as shown in the subject. I've tried searching, and it seems the signature for the original function matches the one I have, and all other solutions I've seen uses the same signature.

View 3 Replies

MVC :: Use SelectListItem For Default Selected Item On Page Load?

Mar 7, 2011

how to make a item the default from a dropdownlist, I want to make the value GBP as the option selected when the page loads, i've spent all day trying to get ddlist to work and now i'm stuck on this.

this

.ViewData["ddlCurrency"]
= new
SelectList(ws.ToList(),
"dboCurrencyID",
"dboCountry",
new
SelectListItem
{ Selected = true,
Text = "United
Kingdom (GBP)", Value =
"GBP"
});

View 1 Replies

MVC :: Modelbinding / How To Save The Value

Feb 3, 2010

I got a ActionResult method that returns a View that it populates with a class object.

On that view I got a submit button and I call another actionresult method that takes the class object as an parameter.

I understand that you have to implement a modelbinder for that class if you need to retain the values.

But i dont understand how it saves the values from previous methods.

For now i put the object in a session object, but i have a book(Pro ASP:NET MVC Framework" from Apress, and in there they say that you dont have to put anything in a session object. But they dont show how else to do it.

View 13 Replies

MVC :: How To Increase Modelbinding Performance

Sep 7, 2010

Does Modelbinding increase performance that much? I have a large table which I have split into 4 details/edit screens, and want to load only information that is needed on the particular screen.

View 1 Replies

MVC :: How To Proceed With Non-sequential Modelbinding

Jun 16, 2010

I am having a table in which i`m dynamically creating and deleting rows. How can I change the code such that the rows be added and deleted and the model info property filled accordingly.

Bearing in mind that the rows can be dynamically created and deleted, I may have Info[0], Inf0[3], info[4]... My objective is to be able to bind the array even if it`s not in sequence.

Model

[Code]....

Controller

[Code]....

View 1 Replies

MVC :: ModelBinding With Foreign Keys?

Feb 22, 2011

I have an MVC3 with EF4 project. I have a screen for order .Order has 2 id's inside it for Billilng and Shipping AddressID .When I go and create a new order these fields render as single textboxes as Ids'Question is how can I render full address textboxes (addressline1,city,state,zip etc) do I have drop in the html markup for them? In that case while capturing the data back I willl have to go with classic way of retrieving name/value pair and then do insert into address bring back that identity and update the order record...?

Create(int customerID,FormCollection fc){}

So the main question is how can I do ModelBinding with foreign keys?

View 8 Replies

MVC :: Array Is Null Upon Posting / Modelbinding

Jun 15, 2010

I have the following codes and the test value is always null in the controller after the post. What is wrong and how can I correct it?

The values of Color, Size, Clothes are posted with the expected values. Though Data.test contains the values, I`m having Object {test=}, in firebug and test is null in the controller. why is that so?

[Code]....

[Code]....

[Code]....

View 10 Replies

MVC :: ValidationSummary Still Works, But Not ValidationMessageFor On My Pages When I Use Modelbinding?

Aug 11, 2010

Let's say I have a property and a textbox on a view

[Code]....
I don't understand why each time I use the modelbinding validation like this

[Code]....

I still get the error displayed, But this time only by Html.ValidateSummary(). the textbox is not highlighted anymore and Html.ValidateMessageFor() doesn't display any message at all.

Is there something I should do the solve this problem? It's important because I have many form that user need to fill out. It's important to highlight the textbox to make it obvious to them.

View 2 Replies

Security :: Custom Membership Provider Error "Could Not Load Type Custom.AspNet.Membership.PostPropertyProvider"

Jan 5, 2011

This is my first membership provider; I converted the sample provider [URL] to SQL. I created a vb class provider and put it into the App_Code folder. After it was created I tried to modify my webconfig but the error pops up. I don't know what else to try, I don't know if I have missed something

webconfig:

[code]....

View 1 Replies

MVC :: Strongly Typing View To Custom Type?

Dec 31, 2010

I am integrating asp.net mvc with an existing asp.net web form application. All works well until I try and inherit my view from custom type.

[Code]....

Reference has been added to the assembly containing the above namespace to the web form project. I had manually create an aspx page since the mvc view templates are not available in web forms project. I guess the way view gets bound to the object by telling it where to inherit from or does asp.net mvc performs some hidden plumbing. There weird part was that I could not even bind it to IList<string>.

View 9 Replies

Ajax - Custom 'Type' In Compare Validator?

Oct 19, 2010

How to reset date Type for Compare Validator in ASP.Neti am using the dd/MM/yyyy format for the Calendar Extender of a textbox, where as Compare Validater looks for MM/dd/YYYY format.so how to change date format of Compare Validator.

View 1 Replies

Custom Server Controls :: Could Not Load Type 'TT.Bar'?

Jun 25, 2010

I copied the ascx,ascx.cs and ascx.designer.cs from another (our old site) website into the new site but i am gettin the error on the 1st line of the control:

<%@
Control
Language="C#"
AutoEventWireup="true"
CodeBehind="Bar.ascx.cs"
Inherits="TT.Bar" %>

View 3 Replies

MVC :: Custom Strong Type HTML Helper For Checkboxes?

Oct 1, 2010

MVC contains a strong typed HTML Helper (HTML.CehckBoxFor()) this takes a bool and returns a bool. To make the URL smaller I am thinking to change the bool values on the model object to byte or somthing like that so the url only contains &Parameter=1.

I have found this snippet :

[Code]....

But I have no clue how to turn this in to a strong typed HTML Helper for checkbox that takes byte instead of bool. Its also important that the model object is set with byte instead of bool.

View 3 Replies

Custom Type Within ArrayList Inside Of The User Profile In C#?

Jan 22, 2010

I'm getting the following error when trying to save a custom class within my ArrayList within my user profile:

There was an error generating the XML document. ---> System.InvalidOperationException: The type Com.xxx.MyDataClass was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.

My web.config has something like:

<profile enabled="true" automaticSaveEnabled="false" defaultProvider="xxxxxxProvider">
<properties>
<add name="MyData" type="System.Collections.ArrayList"/>
</properties>
</profile>

I am trying to store my class called (something like) MyDataClass in an ArrayList into MyData. When I save I get the error above. The class MyDataClass has just two members for now, both set as 'string'.

I assume I have to tell the class has to serialize itself but I'm not sure how.

Here's the class:

namespace Com.xxxx.DataClasses
{
public class MyDataClass : ISerializable
{
public string elem1;
public string elem2;
public string Elem1
{
get { return elem1; }
set { elem1 = value; }
}
public string Elem2
{
get { return elem2; }
set { elem2 = value; }
}
....

UPDATE: FIXED

I was able to fix this issue via the following:

First of all here is a good resource: http://msdn.microsoft.com/en-us/library/d8b58y5d.aspx

I changed the profile entries to be:

<profile enabled="true" automaticSaveEnabled="false" defaultProvider="xxxxxxProvider">
<properties>
<add name="MyData" type="mypackage.MyDataClass" serializeAs="binary"/>
</properties>
</profile>

and then I created MyDataClass to contain a List<> of MyDataClassInfo objects similar to:

namespace Com.xxxx.DataClasses
{
[Serializable]
public class MyDataClass
{
List<MyDataClassInfo> myDataClassInfo;
public MyDataClassInfo()
{
myDataClassInfo = new List<MyDataClassInfo>;
}
public List<MyDataClassInfo> MyDataClassInfo
{
get;
set;
}
}

[Serializable]

public class MyDataClassInfo
{
public string elem1;
public string elem2;
public string Elem1
{
get { return elem1; }
set { elem1 = value; }
}
public string Elem2
{
get { return elem2; }
set { elem2 = value; }
}
....

The key here was 1) using the serializeAt="binary" and 2) using a class which contained a list instead of a list within the profile.

View 2 Replies

Web Forms :: Designing A Custom Control With Different Type Of Button?

Jan 29, 2011

I would like to get help on designing a custom Control with different type of button etc...url=http://postimage.org/image/upi8l8g4/][img]http://s3.postimage.org/upi8l8g4/site_login_box_full.jpg[/img][/url]is all should be Image?how to set the background?Round edges of the Control panel..?the background of its header...

View 8 Replies

Web Forms :: Could Not Load Type Custom Role Provider

May 7, 2015

I am new to asp.net and I have a system am trying to edit but each time I debug it, I get errors. The one of the errors is shown below: Server Error in '/starBus' Application.

Configuration Error.An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message:

Could not load type 'CustomRoleProvider'.

Source Error:

Line 74: <providers>
Line 75: <clear/>
Line 76: <add applicationName="/" name="CustomRoleProvider" type="CustomRoleProvider"/>
Line 77: </providers>
Line 78: </roleManager>

Source File:

C:UsersGayancyDesktopstarBusweb.config Line: 76..Below is the web.config codes with Line 76 in bold:
<?xml version="1.0"?><!--

Note: As an alternative to hand editing this file you can use the web admin tool to configure settings for your application. Use the Website->Asp.Net Configuration option in Visual Studio. A full list of settings and comments can be found in machine.config.comments usually located in

WindowsMicrosoft.NetFrameworkv2.xConfig --><configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

[code].....

View 1 Replies

C# - Object Of Type "customObject" Cannot Be Converted To Type CustomObject Error When Invoking A Custom Object

Apr 12, 2010

i am receiving the follwing error when i am invoking a custom object "Object of type 'customObject' cannot be converted to type 'customObject'." Following is the scenario when i am getting the error i am invoking a method in a dll dynamically. Load an assembly

CreateInstance.... calling MethodInfo.Invoke() passing int, string as a parameter for my method is working fine => No exceptions are thrown. But if I try and pass a one of my own custom class objects as a parameter, then I get an ArgumentException exception, and it is not either an ArgumentOutOfRangeException or ArgumentNullException. "Object of type 'customObject' cannot be converted to type 'customObject'."....................

View 2 Replies

Using Custom Class With Method That Takes Generic Type Parameter

Apr 23, 2010

I have several custom classes that derive from a common base class so they share several members in common. I would like to be able to pass objecs from any of these three classes to a function that will "look at" common properties. However, it seems there is a catch 22 -- When I try to access a member (.FirstName) of the passed object, the computer reports an error that it thinks the member doesn't exist.

It seems to be a sort of contradiction -- since I didn't declare the type, the computer can't confirm existence, but it seems that it should have to take it on faith since the generic character of the type is specified by the code. Possibly there is something I don't know about that would fix this. I'm showing VB code for what I have so far. I went ahead and hardcoded an instance to confirm that the object exists and has the needed property. I commented out the line that had the code that resulted in the computer reporting an error.

[Code]....

View 2 Replies

Security :: Data Type Conflict And Custom Table Merger

Jan 4, 2011

I merged my website tables with ASPNET.db tables using aspregedit.exe. Problem is the user id in aspnetdb user table differs from userid in website table in datatype. One is Uniqueidentifier and the other int. I tried changing the datatypes accordingly, but unsuccessfully. Do I have no option than to re create all my website tables to match the data type in aspnet.db database?

UserId in custom website table is int. UserId in aspnetdb is uniqueidetifier. UserId in custom website database is the primary key and FK in more than one tables, so thats extensively used in the custom database.

View 3 Replies

Custom Master Pages In WSS3.0 / SharePoint 2007 DOC TYPE?

Mar 23, 2011

I have a custom master page that I use in WSS3.0 (SharePoint 2007) and I am using a HTML 'DOC TYPE' which I am declaring at the top of the master page. The site all works very well with my master page apart from some of SharePoint controls which are acting a little funny, namely the People Picker for a People and Group field.If I remove the DOC TYPE declaration then the People Picker and other controls work perfectly and behave as they should but it sends some of my customisations/layout all over.

Before I spend a lot of time reviewing fixing the issues I get to my design without having the DOC TYPE declared, does anyone know if there is a certain DOC TYPE that is compatible with WSS3.0 / SharePoint 2007 and all of its features (i.e. People Picker Fields)?

View 1 Replies

Security :: Custom Membership Provider Error, Can't Load Type?

Mar 11, 2010

I've create a custom membership provider

[Code]....

and on web.cofig file

[Code]....

and I tried also

[Code]....

View 4 Replies







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