Users Pricing

forum

Home Forums String to object (MVC model binding) – MindStick

String to object (MVC model binding)

Samuel Fernandes 3388 10 Apr 2014

So I have a string. And I have a Type, and a property name. Is it possible to convert the string to an object according to the current model binding rules for Type and propertyName in a controller?

For example, I have this model:

class foo {

  [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM dd yyyy}")]

  public DateTime Date { get; set; }

}

, and this string:

"01 01 1970",

and I have the value of typeof(foo), and I have the name of the property, "Date".

How can I convert it to an object (DateTime) according to the current model binding rules and model rules?

Thus, I need something like:

object GetModelProperty(string input, Type modelType, string propertyName) { ... }

Thanks!


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md