MVC :: Deserializing Nullable Model Properties?
Aug 16, 2010
I'm posting Json data to an action that has a model class as a parameter using the
JsonValueProviderFactory. Everything works except for any nullable properties in the model, such as double? and bool? - they always materialize as null, even if a value is posted.
I'm not sure if this issue is specific to the JsonValueProviderFactory, or MVC in general.
View 3 Replies
Similar Messages:
Jan 25, 2010
I have a ASP.NET MVC view that displays a single ServiceProvider object. In this view there is a selectlist that lists one or more ServiceProviderGroup objects and uses the Id property for the value and the Name property for the text. In this list I also show a entry with a value of -1 and text of "No Provider". When the Edit[Post] method is called the Id value from the select list maps to a nullable property (GroupId) on a ServiceProvider object. When a value other the -1 is selected from the list it works as expected. But, when the value is -1, I want a NULL reference to be applied to the GroupId property during the UpdateModel call. Within the Edit method, prior to calling UpdateModel, I have tried replacing the entry within the Controller.ValueProvider with a null reference and adding a ValueProviderResult which contains a null reference, but the UpdateModel always has an issue (InvalidOperationException).
View 3 Replies
Oct 27, 2010
I have a problem with passing a model to a controllerIn my controller I have a HttpPost function that gets a EF model.The problem is that the form does not contains all properties of the EF model.When the function is called that gets this EF model, I get error messge of fields that are not nullable in the EF model.That's because the fields are not in the form, so the not nullable properties gets no value.
View 5 Replies
Apr 1, 2011
I have a problem:
I've created usual Controller and View(Edit view) for editing my Entity (EntityFramework)
Here is view example:
<div class="editor-field">
@Html.EditorFor(model => model.BirthDate)
@Html.ValidationMessageFor(model => model.BirthDate)
</div>
BirthDate is Nullable<DateTime>
but during loading my View I get this exception
The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'.
That's because of BirthDate is null in database but it is nullable and I expect that it just leaves the filed empty.
And I have Shared EditorTemplate:
@model System.Nullable<System.DateTime>
@if (Model.HasValue)
View 2 Replies
Nov 10, 2010
I've written the following Extension Method
<Extension()>
Public Function ToUtcIso8601(ByVal dt As Date) As String
Return String.Format("{0:s}Z", dt)
End Function
But I also need a Nullable version of the same method... how exactly do I do this?
This is what I was thinking, but I'm not sure if this is the right way
[code]....
View 1 Replies
Sep 13, 2010
Im just wondering how you go about creating dynamic properties on entities that generated from a database generated model.For example I have a UserInformation table. In that table it has basic information on the user (well derr) like user name, address details etc etc. I want to add a readonly property that concatenates the user's Name, Address details and Phone Number into one string that I can output to a view. Any ideas on how i would go about creating this dynamic property. This is just a simple example, i am wanting to do some more complex calculating and concatenating.
View 1 Replies
Jul 14, 2010
I need to bind a bunch of properties over my model entities. All of them uses the List<T> class. I already managed to write a model binder that can treat individualy types derived from that class, but i can't set the value of this property on the model. every time i check the model afer the bind process i see a list with 0 itens.
Here's how it runs.
After i post the values the model binder catchs up the types for bindingAt the custom model binder i check if this property is a List<T> typeIf it is then i perform the bind like it have to be, if not i let the default binder do the job.Finally i return the object binded. What happens next is the issue i've mentioned "i see a list with 0 itens" on the Model property.
Here is the code of Custom Model Binder:
[Code]....
View 1 Replies
Mar 31, 2010
I'm reading a bit of Pro ASP.NET MVC Framework and following a few tutorials written in the book. In the very first tutorial, creating a MVC site for dinner (PartyInvites), I encoutered this problem. While I try to reference some properties from Model class, the compilation error occured. Eg. the following code failed.
[Code]....
and the error message
Compiler Error Message:
CS1061: 'object' does not contain a definition for 'Name' and no extension method 'Name' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) I imported the Model folder into the controller too. I dunno what I'm missing here. Sorry, if it sounds a bit umm hard to understand cuz I just started picking up MVC this morning. Looking for any input.
View 5 Replies
Sep 13, 2010
I'm trying to build a link to an external website using some properties of my model class in my view page, e.g. I want it to render as something like -[URL]where post-id would be pulled from the model (I'm using a strongly typed view model here - I can't use ViewData as there's a list of items being pulled back all of which need seperate links).I tried doing < a href="<% model.PermaLink(); %>">, where PermaLink is just some string, however the value doesn't get picked up.If I try < a href="<%= model.PermaLink %>">, I get an error - CS1502: The best overloaded method match for 'System.IO.TextWriter.Write(char)' has some invalid argumentsIs there any way to do this? I tried adding the runat="server" attribute, however this just linked to my local site and controller/model actions.
View 2 Replies
Mar 22, 2011
how can i apply string.trim() accross the website when saving or editting data on the model rather then on individual fields accross the site in the controller.
View 2 Replies
Dec 3, 2010
I have a strongly typed view. I get model passed into the view and then i assign model values to labels etc.
I would then also like to set Model values programmatically on .aspx page, like:
<%= Model.someValue = "foo"; %>
and then pass that model back to controller action and than access those values. I know that I can apply values to model like these:
<%= Html.TextBoxFor(n => n.someValue) %>
but in these case, this is not an option for me.
View 2 Replies
Mar 30, 2011
When it creates a view using the list scaffold the headings are hard coded. I want to pull the headings from the data model, but no luck. I was assuming LabelFor would be the solution. I must be missing something basic.
View 2 Replies
Jan 4, 2011
Note: I'm working with MVC3 RC and Razor views.I've got this model:
[Code]....
I want to have a strongly typed create view for this model, that allows you to insert 1 to many addresses and phone numbers as part of the view. Ideally, the Action is strongly typed as well:
[Code]....
What would this view look like to facilitate creating 1 to many Addresses and PhoneNumbers, as well as having the state re-created correctly if the ModelState fails when posting? I've tried a number of variations including EditorTemplates and can't figure out how to do this.
View 1 Replies
Mar 18, 2011
I have a view that is strongly typed and its model is of type LogOnModel. That LogOnModel has anotated properties like this one:
[Required(ErrorMessage = "Please enter your password")]
[DataType(DataType.Password)]
[Display(Name = "Password", Description = "Your secreet password")]
public string Password { get; set; }
All of them has Display anotation with Display.Descripion property set. I want to create HtmlHelper extension method that will output <span> containg the value of Display.Description property. So for example if I called my extension method DescriptionFor than this code:
<%: Html.DescriptionFor(m => m.Password) %>
should produce following html: <span>Your secreet password</span>
View 1 Replies
Mar 29, 2011
I have an issue with deserializing an object. I get an error 'System.Int32' cannot be converted to type 'System.Decimal'. This object has many child objects and since this object has been serialized, a new version of the object has one or many fields that have been changed from int to decimal and now I can't deserialize the object because it doesn't match my original object.
I have tried using the OnDeserializing method but the context parameter.
Is there a way around this? I've found some examples online but it doesn't really apply to my situation. I would just like to know if there is a way to view my serialized object even if my object has now changed or if there is a way to find out which variable needs to be changed to decimal and how to go about doing it.
I've added your code but I'm not quite sure how to call it from my code. Here's what I've got:
public static Application LoadSnapshot(int appID, int statusID)
{
ApplicationSnapshotCollection AppSnap = new ApplicationSnapshotCollection();
AppSnap.LoadByAppAndSnapshotStatusID(appID, statusID);
[Code]....
How do I go about calling the constructor with the proper parameters in my scenario?
View 1 Replies
Mar 29, 2011
I have an issue with deserializing an object. I get an error 'System.Int32' cannot be converted to type 'System.Decimal'. This object has many child objects and since this object has been serialized, a new version of the object has one or many fields that have been changed to decimal and now I can't open or view the object because it doesn't match my original object. Is there a way around this? I've found some examples online but it doesn't really apply to my situation. I would post some code but I don't think it would really help...I would just like to know if there is a way to view my serialized object even if my object has now changed and how to go about doing it.
View 2 Replies
Feb 28, 2011
I've been trying to deserialize the following JSON output into a vb.net object:
[Code]....
The following is what i've done so far:
[Code]....
I have problems reading the array value of "t". I'm quite sure that the problem lies in the PageTags() but i'm not sure how to go from here.
View 3 Replies
Feb 22, 2011
I am really struggling deserializing a PHP json encoded string in ASP.NET.I am using nusoap and CakePHP 1.3 on the PHP side and mvc.net 4.0 on the web service side and everything was working well. However, I couldn't figure out how to pass a complex array as one parameter of the webservice, so I had the idea of serializing it as json and passing a simple string. So far so good...
$args['products'] = json_encode($booking['Booking']['prs_products']);
[code]...
View 1 Replies
May 13, 2010
I'm trying to store some business objects in a SQLProfileProvider Profile property, however my business objects use public properties, not fields. This means I can't serialize as binary (correct?) so I'm serializing as XML. I've got the basic XML.Serialization attributes on the business objects, basically just XMLRoot and XMLElements with Type properties and an XMLArray attribute for a collection<T>. When I look at the data in the aspnet_Profile table, sure enough, it looks like an XML representation of my BOs:
[Code]....
Additionally, it works fine while the user is logged in.However, if the user logs out and logs back in, the profile property is a new instance of the BO, not what was saved in the profile. What am I missing here?
View 1 Replies
Feb 11, 2011
I have an ASP.NET 4 web app that is using the Entity Framework to hold, amongst other things, a hierarchical structure of items that is used for features such as navigation.
One of the functions of the application allows the export of a particular branch of the hierarchy tree to XML, generated using a DataContractSerializer. Once exported, the intention is that the XML can then be uploaded to another instance of the same app, deserialized back into EF objects and then added to the data model on the second server.
When I try and import data in this way, I'm finding that I see the following error:
The object could not be added or attached because its EntityReference has an EntityKey property value that does not match the EntityKey for this object.
Taking a closer look at the XML that is generated by the serializer, I can see that the entity key is among the items that has been serialized. Since I'm importing entities that originate from a different database, some of the ID's clash.
What I'd ideally like to be able to do (unless I'm missing something here) is attach the imported entities to an object context and reset the ID's of the objects being imported.
Is there a smart way to do this? Do I simply have to set the ID for each of my imported entities to 0, attach them to the object context and then save changes?
View 1 Replies
Nov 3, 2010
I have a new VS2010 .NET 4.0 Web project and the Properties Folder has gone wierd on me. It has lost teh "Open" under the right click. There is no way to get a Settings file created now.
I am unable to get to the Settings grid and no Settings file is created. I tried the help and it has the normal trip of select Properties, Open (right click), Settings Tab, etc. etc.
View 1 Replies
May 19, 2010
I'm building an MVC 2 RTM app, and I want to be able to share my model across applications. I'd *like* to be able to implement it like:ASP.NET MVC2 app (holds Views and Controllers)Class library to hold Model(s)WCF app to handle the data transactions with the models via different data stores across apps I had the MVC app working fine, but I wanted to abstract the data stuff and be able to work with the model across apps through the WCF site, so I created a class library project and moved all of the Models classes into that and set-up a WCF app, then added project references to the MVC and WCF apps that point at the class library. The idea was I can create services that take and return objects from the model via method calls across apps. It appears that everything's wired up correctly in the MVC project, so I'm passing the objects stored in the Models class library between controllers and views and everythig is compiling just fine, but for some reason the data is not being passed back from the views to the controller on POST -- all of the properties in the classes are null or empty.
When I debug the app, I can see that the values are stored in the model data dictionary but not the model object itself. What am I doing wrong? Am I on the wrong path, or missing something obvious (to some)?
View 2 Replies
Sep 1, 2010
Is it possible, inside a Custom Model Binder, to fire "something" that "says" the value is invalid so it gets handled by validation part?
Basically, I am getting an exception when the value for the property is invalid.
View 1 Replies
Jan 10, 2011
I made a few changes to the DB in SQL server management studio then right clicked on the .edmx doc to get it to update. That seemed to work fine but when i compiled the app everything that referenced the EF seems to be broken.The Error list now contains the below error for all classes that used it.
The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?)
View 4 Replies
Mar 11, 2010
I have an issue of static variable in an asp.net application. Let's say I have a server with 8 CPUs running windows 2008 R2 hosting an asp.net webbsite, nothing fancy here, no funny configuration.
Is the following statement true? at any single time, there's one and only one process is running and accepting requests, even in the recycling stage. The reason I am asking is: I have a static field in my class, and I want to make that's the only static instance in the website. I've heard in some circumstances, IIS is recylcing your application, and it will start a new process, but the old process is still working, thus I will have 2 static instances in memory, which defeat the purpose of static field.
One step further, let's assume there might be 2 instances in memory, can I assume there are at most 2 instances at any single time? And can I assume once the second instance is up, the first instance will NEVER accept new requests?
Another question: Recently I have a problem with an applicationdomain concept. Looks like if an application domain causes a memory leak, unload the domain will not release the memory (Umanaged leak). So to what extent Application Domain is isolated?
View 1 Replies