Calling Index view is giving me this very very annoying error . Can anybody tell me what to do about it
Error:The model item passed into the dictionary is of type 'System.Collections.Generic.List1[MvcApplication13.Models.Groups]', but this dictionary requires a model item of type 'MvcApplication13.Helpers.PaginatedList1[MvcApplication13.Models.Groups]'.
public ActionResult Index(int? page) { const int pageSize = 10; [code].....
Got a nullable datetime member on my viewmodel.the moment it hit my controller action, the viewmodel's modelstate allready are invalid (because the member is null).Forgot...how that works? (using MVC2)Basically my viewmodel have a social security number, passport number and passport expiracy date.If the ssn is entered, I want to ignore the two passport related fields, so I made the expiracy date member nullable.
Like all other viewmodels in this app, each model have it's own validation function that will do validation, and in there I add an error that the date is required or not valid (if using passport number). mvc itself should not care about the date at all.I dont want to give the date a default value, because then the date will show when the form loads, and it must be an empty field (unless I already got a date of course.
Am I going to be able to query (using LINQ to SQL) a database field with a type like the following "public System.Nullable<System.DateTime> Spouse_DOB"?
I'm trying to use the following code: [Code]....
and I get the error "'System.Nullable<System.DateTime>' does not contain a definition for 'Month' and no extension method 'Month' accepting a first argument of type 'System.Nullable<System.DateTime>' could be found (are you missing a using directive or an assembly reference?)"
Is it because this DateTime column allows a NULL value (since everyone isn't married in my database)?
Error 1 'System.Nullable<System.DateTime>' does not contain a definition for 'Month' and no extension method 'Month' accepting a first argument of type 'System.Nullable<System.DateTime>' could be found (are you missing a using directive or an assembly reference?) C:Working WebsitesGrannys Clan Address BookDefault.aspx.cs 38 26 C:Working WebsitesGrannys Clan Addres
I am making a website to store invoices so i can mail them to clients. So i got a table for clients, invoices and one with invoice products/services. When an invoice has no products/services added to them and it returns null i get the error "the null value cannot be assigned to a member with type System.Decimal which is a non-nullable value type."
I just started with linq. Before i always used mysql. Mostly i just had to call data from 1 table so forgive me if my linq query isn't really correct.
Dim invoices = From i In db.invoices _ Group Join p In db.products On i.id Equals p.invoiceId Into invoiceProducts = Group _ Select New With {i.client.naam, i.titel, (From iP In invoiceProducts Select iP.prijs).Sum}
i show the client's name, the title of the invoice and the total amount the clients will need to pay for products and services.
Above is my code. The error I'm get is, Unable to cast object of type 'System.DateTime' to type 'System.String'.
The column "To" and column "Subject" are strings and column "Receive" is DateTime. I can't made any changes in the database, so I need to write some code to handle casting a string to datetime or if statement as a work around.
Members 'System.DateTime modDate' and 'System.DateTime insertDate' both marked as row version.modDate and insertDate is a SQL Server database field with smalltimedate as data type.
i having error throw on View page and i think i am passing wrong type.
The model item passed into the dictionary is of type 'System.Collections.Generic.List1[App.Domain.Model.Interface.IPerson]' but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[App.Domain.Service.PersonService]'.
MyService looks like this....
namespace App.Domain.Service { public class PersonService : IPersonService [code].....
I have a asp.net mvc view which is strongly typed view and i have a controller which returnsthe ilist user based on the id provided. I am getting the following above error:
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[Data.User]', but this dictionary requires a model item of type 'Data.User'.
I am new on MVC and i trying to learn it. My project its about a e-store...
But i got this error:he model item passed into the dictionary is of type 'baraMjukis.ViewModels.ProductViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[baraMjukis.ViewModels.ProductViewModel]'. And here are my code:
When i click on the page that represents a controller the following error was displayed:-
"The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type"
On this link of code
var articleapproval = articletyperepository.FindAllArticlesRequireMyApproval().ToList(); while the FindAllArticlesRequireMyApproval execute the following LINQ statement :- var articleapproval= articletyperepository.FindAllArticlesRequireMyApproval().ToList();
where this methods calls the following LINQ statement:-
I am LINQ querrying against a datatable. However, I am unsuccessfull with catching null values. Here is my code that is giving me the following error.
[Code]....
I am checking to see if minperc is null. However to check that it still is trying to convert the value to double. Cant figure out a way around it. Here is the error: Cannot cast DBNull.Value to type 'System.Double'. Please use a nullable type.
I'm using MVC 2 with some Models from a LinqToSql project that I built. I see that when I post back to a Controller Action after editing a form that has a DateTime field from the Model, the MVC Html.ValidationMessageFor() helper will nicely display an error beside the Date text box. This seems to happen automatically when the you test ModelState.IsValid() in the Controller Action, as if the MVC model binding automatically knows that the DateTime field cannot be empty.
My question is... I have some other string fields in these LinqToSql generated classes that are Not-Nullable (marked as Not Nullable in Sql Server which passes thourgh to the LinqToSql generated classes), so why doesn't Mr. MVC pick up on those as well and display a "Required" message in the ValidationMessageFor() placeholders I have added for those fields?
Sure, I have successfully added the MetadataType(typeof<t>) buddy classes to cover these Non-nullable string fields, but it sure does seem redundant to add all this metadata in buddy classes when the LinqToSql generated classes already contain enough info that MVC could sniff out. It MVC validation works with DateTime automatically, why not these Not-nullable fields too?
I am a c#/asp.net developer and I am having to work on a VB/asp.net. I started out with VB.NET but after years away from it I'm getting confused with the syntax.
I have two variables
Dim originalDate as DateTime? Dim newDate as DateTime?
Both nullable datetimes, originalDate is a nullable date I am getting from the database and newDate time is set in code, I need to compare them, they can either both have dates, neither have dates or one have and one not.
I have a bit of code as follows:
if origEndDate = origEndDate then
When both origEndDate and origEndDate are "nothing" this statement is false (well when I run it in the watch window it comes back as nothing)!
I don't understand why this is the case because I was under the impression doing an "=" compares the two values and as they are the same surely it should be true?
What syntax should I be using as in C# I can do the above as so:
I have a textbox that I use to gather a date. I would like to have the database store a null if this field is left blank by the user when submitting. I am using the following on my aspx page:
Every single parameter is bound just fine except toDate which turns out to be always null. When inspecting the Request.QueryString["toDate"] it retrives the right value which is 30/09/2010. It seems that DateTime expects another format when binding. What is the right format?
Is there a way to use the OrderBy command in Linq with a DateTime field using the Date portion only (without the Time Stamp portion) that is nullable such as in the following query?
var query1 = from myTable in MyTable where myTable.EnteredDate != null group myTable by myTable.EnteredDate into myOutput[code]....
Since myTable.EnteredDate is a DateTime field that can contain nulls, it does not support the .Date conversion call such as myTable.EnteredDate.Date
Is there a way to convert the myTable.EnteredDate field into a date only string in the group by portion?
I am having a problem with the Client Validation not firing when I have marked a nullable DateTime field as [Required] and the value of the field is null. (It is actually stopping ALL client validation on the page working - not just the DateTime field).
Interestingly enough, once a post back has been done and the error picked up on the server, the client validation starts working.
Also if you set the date to a none null value (see commented out line in the controller) it will also work
I have replicated this behaviour in a small test project (this is deliberately very Noddy - just enough to replicate the problem)
Am I doing something fundamentally wrong or am I looking at coding some sort of work around here? (I realise that a Required nullable field sounds like a bit of a oxymoron, but I wanted to present the user with a blank field which they must then fill, not one pre-populated with an arbitrary date value)
I have setup my business object to have a create_date and edit_date members both datetime datatypes. My company want to display the create_date and edit_date fields in a gridview for each transaction. The problem i have is that after insterting a record it will have a valid create_date but no edit_date and when displayed in the gridview it defaults to datetime.minvalue (My default). How on earth do i show an empty field in my gridview for a null datetime field in the database?
I am using similar architecture to the Imar Spaanjaars example of a tiered solution. With a few small tweeks it has worked well for me for ages. I am passing a List<Database> to my object datasource which connects to my gridview.
I have this error "The given value of type String from the data source cannot be converted to type datetime of the specified target column." when I used sqlbulkcopy to do the transaction
I created a UserControl and added a public DateTime property. I want to set this property in Markup (ie. <cc1:MyControl runat="server" id="MyControl1" DateTimeProp="1/1/2010" /> ) however I live in a place with a dd/mm/yyyy date format so it complains if I set something like "20/1/2010". Is there a way to set markup in my local datetime format or do I have to conform to "mm/dd/yyyy"?