English 中文(简体)
我怎么做。 文本BoxFor Time接受d用户的投入。 MM.y
原标题:How do I make Html.TextBoxFor DateTime accept user input of dd.MM.yy

我试图翻一页,使用户能够搜索文章。 可以选择根据<代码>FromDate和限制查询。 两者均为<代码>Datetime

请用户在<代码>d后填写。 MM.yyy,因为这在我国是正常的。 在提交表格之后,我可以看到《欧洲刑法》中的日期,而且我想到的是。 但问题是,MVC3假设格式为MM.dd.y。 我如何能够改变这种状况?

Some code: This is the Razor code I use

<div class="toDate" >
  <label>til dato</label>
  @Html.TextBoxFor(m => m.DateTo, new { placeholder = "dd.mm.yy" })
</div>

在模式中,我有:

public DateTime DateTo { set; get; }

我已尝试使用编辑稿,但我失去我的持证人文本。

www.un.org/Depts/DGACM/index_spanish.htm 简言之,我如何使我的MVC3模式接受用户关于表格的日间投入。 MM.yyy

If my question isn t clear enough, let me know and I ll try to clarify.

EDIT: It appears that I need some clarification, so I ll try to do that by making a scenario:

  1. The user enters his search criteria. He sets a DateFrom and a DateTo in two text boxes.
  2. The form is submitted and posted back to the server.
  3. On the server the DateTime object is treated on the form MM.dd.yy. I wish for it to be interpreted as dd.MM.yy.

我希望能够提供帮助。

问题回答
[DisplayFormat(DataFormatString = "{0:dd MM yy}")]
pubilc DateTime DateTo { get; set }

如果你根据你所熟知确定的日期格式,则确定一种习俗验证归属。

Here s a nice tutorial for it: http://msdn.microsoft.com/en-us/gg618485 (It s not as difficulty as it might seem at first, and can be really helpful).

或者仅仅建立具有以下特征的验证制度:

RegularExpression(@"[0-3][0-9].[0-1][0-9].[0-9][0-9]")]

优于reg,但是一个例子。

Edit: 如果3nigma ,你的解决办法显然比地雷更可取。





相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签