0

I have the following:

public class myViewModel
{
  [DisplayName("User ID")]
  [DataType("string")]
  public MyCustomDataType UserID { get; set; }
}

I want to define MyCustomDataType as a user defined data type and have my getter and setter handle the data based on DataType. ie: if string, return string...etc. How can I define MyCustomDataType so that it is aware of field's DataType? And how would I define the getter and setter?

The reason behind this is I want to mask certain fields that contain senstive data. This is related to this post

Community
  • 1
  • 1
user2708543
  • 39
  • 1
  • 5
  • Add some pseudo code to clarify, show how it should operate. Currently it is unclear. – H H Aug 29 '13 at 15:01
  • I don’t want the viewModel to contain the actual UserID value. What Im looking to accomplish is to use the session as a transition to store and retrieve the data fields So my custom data type would look something like this. Public class MyCustomDateType { get { //use the token to get actual value from session. //Cast value using DataType defined in ViewModel //return value } set { //store value in a custom session module which returns a token } } – user2708543 Aug 29 '13 at 15:13
  • Sorry I cant seem to figure out how to format the code block – user2708543 Aug 29 '13 at 15:16

1 Answers1

1

There is no need to use [DataType].

All you need to do is to create an editor template, which is used for forms, and a display template (which is used to display your custom data type).

You can say that they are custom views which will be included automatically when you use Html.DisplayFor and Html.EditorFor in your regular views.

jgauffin
  • 99,844
  • 45
  • 235
  • 372
  • I dont understand how this is going to help me? Im trying to manipulate the viewmodel data before it gets posted – user2708543 Aug 29 '13 at 16:19