Using Html.EditorFor() for custom type in ASP.NET MVC -
i have custom type money viewmodel:
public class money { public money(decimal value) { value = value; } public decimal value { get; private set; } public override string tostring() { return string.format("{0:0.00}", value); } }
and want render textbox in asp.net mvc via html.editorfor(viewmodel => viewmodel.mymoneyproperty)
doesn't work. there special interface have implement in money?
best regards , in advance,
steffen
try this:
public class money { public money(decimal value) { value = value; } [displayformat(dataformatstring = "{0:0.00}", applyformatineditmode = true)] public decimal value { get; private set; } }
and in view:
<%= html.editorfor(x => x.somepropertyoftypemoney.value) %>
or have custom editor template money (~/views/shared/editortemplates/money.ascx
):
<%@ control language="c#" inherits="system.web.mvc.viewusercontrol<appname.models.money>" %> <%= html.textbox("", model.value.tostring("0.00")) %>
and in view:
<%= html.editorfor(x => x.somepropertyoftypemoney) %>
Comments
Post a Comment