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?
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:
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:
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.
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)
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
[System.Web.Script.Services.ScriptService] public class Quotes : System.Web.Services.WebService { ebMethod] public void Calculate(int param1, int? param2)
I spent about 60 minutes sifting through search engine listings trying to figure this out and couldn't find an answer, so I decided to make this post for others.
Situation: Using a Stored Procedure to insert a row and return the new row ID, explained here. In my case, I used the Idenity_Scope to return the new row, like so:
[Code]....
Next, following steps as described in link above, went into the dataset XSD page, configured the table adapter to use this stored procedure. By default, it wanted my return value to be set to some value, but I set to allow Null (makes sense, since I don't want to pass the value in, I want to get it out, so it should be null to begin with).
Problem: Where I ran into an issue was in the method to call this stored procedure. The intellisense displayed the prototype it was expecting, basicly like this:
I have a site that uses a jquery calendar to display events. I have noticed than when using the system from within IE (all versions) ASP.NET MVC will fail to bind the datetime to the action that send back the correct events. The sequence of events goes as follows. Calendar posts to server to get events Server ActionMethod accepts start and end date, automatically bound to datetime objects
In every browser other than IE the start and end date come through as: Mon, 10 Jan 2011 00:00:00 GMT
When IE posts the date, it comes through as Mon, 10 Jan 2011 00:00:00 UTC
ASP.NET MVC 2 will then fail to automatically bind this to the action method parameter. Is there a reason why this is happening? The code that posts to the server is as follows:
data: function (start, end, callback) { $.post('/tracker/GetTrackerEvents', { start: start.toUTCString(), end: end.toUTCString() }, function (result) { callback(result); }); },
I'm working on a forum application using MVC 2.0. I've built a basic page listing all the forum posts, held in a database and I've added a simple section on the bottom for a user to add a new post:
<% using (Ajax.BeginForm("AddChat", "Chat", new { text = Model.AddChat.Text}, new AjaxOptions { OnSuccess = "handleSuccess" })) {%> <%: Html.ValidationSummary(true)%> <fieldset> <legend>Fields</legend> [code]....
I'm trying to call an action method in an MVC application using jQuery. Basically what I want is to take the value of a couple of input fields and call the action method by clicking a button, passing the values of the input fields as parameters. But I only get the value of the "number" parameter, not the "year" parameter.
function selectWeek() { $('#selectWeekButton').click(function (event) { var number = $("#selectWeekId").val(); [code]...
I checked the url with an alert, as you can see, and it seems to contain both values fine. But when I check the value of the year parameter in the action method it is null.Here are the input fields:
public ActionResult Edit(string number, string year) //etc...
I know that this looks like a strange thing to do instead of just binding fields, but the reason is that these input fields and their values is not the main purpose of this View. They're just there to select another week in this timesheet application. And besides, I'm going to replace the input fields with a jQuery calendar eventually, so I will still have to do something like this.
So what's the easiest way to do this, and why isn't it working as it is?
I hope this is the right forum for this question.The statement , object obj = cmd.ExecuteScalar() is returning 2010-10-22 18:25:36However is not bringing the last 3 digits (miliseconds).This is actually calling the following SQL query: select max(timeStamp) from Table1 which returns 2010-10-22 18:25:36.713 on query analyzer. As you can see "713" is not being included ...How do I bring this value?
In the create aspx page i have 2 buttons. One for creating the new customer and another one for searching the customer based on the customer last name. Now the issue is when i try to search the customer based on the last name the page is calling the create action method only, not the search action method. how to call a spicific action method from the buttons. I know it can be done using ajax post back but what i am looking at is to achive this in the normal post back itself.
I have a Visual Studio 2008 solution that when I build, returns the following error:
Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. Parameter name: ticks
There is no reference file/line/column in the error. Becoming quite frustrating as the solution builds in the end, however I cannot debug.In the solution, there is no reference/using to DateTime.MinValue.Ticks at all...
EDIT:
There are only 2 references to ticks in my solution, and neither of those are causing the issue.There are no constructor issues with DateTime either. I do not believe it is related to DateTime or ticks at all.I have found a similar reference where it turned out to be a corrupt image file in the solution, where it did not have a date-modified value. This is not affecting mine though.
i wonder something about mvc post method. for example I created a view "strongly typed" from a model (MyModel).
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Demo1.Models.MyModel>" %> for Create actionsthere is two way. first one takes MyModel as parameter [HttpPost] public ActionResult cart(MyModel md, int someID) { //some code //..... return View(MyModel); } second one does not take parameter as model. [HttpPost] public ActionResult cart(int someID) { //some code //..... return View(Mymodel); }
for first one way, after form post the form values does not delete, I mean form does not cleared,after second one form is be cleared. why this diffirence?
Secondly, how does ASP.NET MVC know that action is my action, and controller is my controller. Like I saw this in samples, and it does work, but isn't it just an anonymous object with no type?
i have a website where i provicde a link. On clicking the link a controller action method is called to generate a zip file after creation of zip file is done, i show the link to download the zip file by replacing the link to create a zip with the link to download the zip.
the problem is that after zip file creation is over and link is shown, when user clicks on the link to download the zip file, they are sent to login. After providing correct credentials in the login page they are prompted to download the zip file. they sould not be sent to the login page. In the action to generate zip file i haven't abondoned the session or haven't not done anything that abondons the session.
the user should not be sen't to login page after successful creation of zip file user should be able to download the file without login. i search internet on this problem, but i did not find any solution. In one of the blog written by hanselman i found this statement that creates the problem with the session: Is some other thing like an Ajax call or IE's Content Advisor simultaneously hitting the default page or login page and causing a race condition that calls Session.Abandon? (It's happened before!)
so i thought there might be some problem with ajax call that causes the session to expire, but i don't know what is happening? it's like this after users click on the link to create zip file the zip file is created successfully but the session gets expired. this is not what i want. Why does the session has to get expired after making a jquery post call to controller action to create a zip file? i hope u understand the problem.
I have a form and I want to insert the current time at which the user clicks to insert into the table of my db. When running, I get the following error when trying to insert into my sqldatasource:
"System.FormatException: String was not recognized as a valid DateTime."
I have created a web service (.asmx) which is working fine locally.Now when a client of ours is trying to access this web servce he receives an error sayinginvalid action parameter.Any idea why this error appears..also will
I have written a code to insert emp details into database and i am also inserting local date(i,e system date) into to the table to know/have an idea at what date the employee inserted details. I have set date format add/MM/yyyy and its working well in my local system, but after uploading the site into server (the server is shared server) iam getting error and the error message is Failed to convert parameter value from a String to a DateTime.
Surprisingly, it is working well in server when i chaged the date format to MM/dd/yyyy, but now its not working in my local system and getting the same error.
I thought this would be easy and maybe it is but it's eluding me.
In an action filter (MVC 2) I want to add/edit one of the parameters for the type I'm passing to my action method.
I have an action method:
[Code]....
Bar is a simple class for viewData:
[Code]....
In my BarFilter action filter OnActionExecuting method I want to add a value for paramA which is not set by the view so that Bar will be fully populated in my Foo action method. I've tried various methods of adding values to ViewData, ModelState, Model etc. but I always get a null returned in Foo.