Hello I find it a better practice to create a component that generates the text on the screen.
Example:
namespace IM.Framework.MVC
{
using System;
using System.Text;
using System.Web.Mvc;
public static partial class IMHelper
{
public static MvcHtmlString IMInputDate(this HtmlHelper html, string Id, string Caption, string PlaceHolder, int Size, DateTime Value)
{
var sb = new StringBuilder();
sb.Append(GeraDiv(new string[] { "input-control", "text", "span" + Size.ToString() }));
sb.Append(IMLabel(html, Id, Caption));
sb.Append(String.Format("<input type='text' id='{0}' placeholder='{1}' value='{2}' class='inputPadrao inputDate' />",
Id, PlaceHolder, Value));
sb.Append(FechaTag("div"));
return new MvcHtmlString(sb.ToString());
}
}
}
In View use instead of
@Html.Raw(item.data.ToString("dd/MM/yyyy"))
utilize:
@IMHelper.IMInputDate("id_do_campo", "Título", 10, item.data)
Remembering that in Iminputdate I use code that depends on other functions not available here. But the idea is just to give a "Light".
Why can’t I use
DisplayFor
norEditorFor
, where using them is the right way?– Leonel Sanches da Silva
I thought it would be a mistake to put them inside Webgrid, but I saw that it works.
– Ton Angelo
@Tonangelo all right, I’d like to know (if you can) what was the scenario of your problem, because in a way when the application is configured correctly many things are implicit and do not even need to be configured. I’d also like to see in your question that
model
and also asks if you have set up globalization of your app? If you can answer perhaps many things can be clarified, even if you have positioned yourself in an answer!– novic
@Virgilionovic I picked up the system recently, the person who had started left the company and do not know how it generated the classes of the database, no type Datetime of the model has Datatype defined and as the database has many tables, it would be impossible to leave changing everything. The Web.Config consta <globalization enableClientBasedCulture="false" Culture="pt-BR" uiCulture="pt-BR" />, but even if you do not pass formatting continues the American format.
– Ton Angelo
@Tonangelo remove from globalization
enableClientBasedCulture="false"
do a test or putenableClientBasedCulture="true"
will realize that will get formatted correctly. I understand you ... !!! makes this setting. and will have many differences!– novic
@Virgilionovic if by chance the client’s computer has OS in another language, this would keep in Portuguese?
– Ton Angelo
@Tonangelo what is worth is what is in your application, all who access your site (app) has the language pt-BR or be Portuguese. Yes language is what you set up, changed something?
– novic
@Virgilionovic changed yes, overall this would almost solve my problem, I still have to set not to display the seconds in all Datetime. But I already appreciate it. This little detail on the Web.Config helped a lot.
– Ton Angelo
@Tonangelo ... !!! realize that if it was configured correctly, even this need not do, but, It is not your fault but who developed first... Guy good luck.
– novic