Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Test of the model type
Message
 
General information
Forum:
ASP.NET
Category:
MVC
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01560569
Message ID:
01560571
Views:
35
>Hi everybody,
>
>This is more of a C# language question, but I want to implement this logic in the razor view.
>
>I found that for my case the ViewData.ModelMetadata.ModelType returned Int16.
>
>So, this is what I started to write
>
>
>@if (ViewData.ModelMetadata.ModelType.ToString()
>
>
>And I am not sure how to finish it. I want to test it against (first 3 chars to be Int or other numerical types (I guess I need to test for decimal)?
>
>Do you know what is the best way to implement this logic?
>
>Thanks in advance.
>
>-----------------------
>By some googling on this topic I found this
>
>
>Type objType = typeof(T);
>
>    if (objType.IsPrimitive)
>    {
>        return (objType != typeof(bool) && 
>            objType != typeof(char) && 
>            objType != typeof(IntPtr) && 
>            objType != typeof(UIntPtr)) ||
>            objType == typeof(decimal);
>    }
>
>
>in http://stackoverflow.com/questions/1130698/checking-if-an-object-is-a-number-in-c-sharp
>
>Do you think I can somehow apply that code to my case?

Found this http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/66a7dc8d-f276-4d45-8da4-f8d9857db52c/ which seems to be what I am looking for - the question now is how to incorporate this into my razor view? If, say, I add the above into some of my helper classes, should I add a reference of that to my view and then use this test in the view?

I think this is what I am going to try.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform