---
title: "String to object (MVC model binding)"  
description: "String to object (MVC model binding)"  
author: "Samuel Fernandes"  
published: 2014-04-10  
updated: 2014-04-11  
canonical: https://www.mindstick.com/forum/2015/string-to-object-mvc-model-binding  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 1 minute  

---

# String to object (MVC model binding)

So I have a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp). And I have a Type, and a [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) name. Is it [possible to convert](https://answers.mindstick.com/qa/96585/is-it-possible-to-convert-a-presentation-into-a-video-if-yes-how) the string to an object according to the current [model binding](https://www.mindstick.com/forum/158590/what-is-model-binding-in-asp-dot-net-mvc-and-how-does-it-work) [rules](https://www.mindstick.com/articles/43901/blackjack-rules) for Type and propertyName in a [controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc)?

For example, I have this model:

class foo {

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

[public](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers) [DateTime](https://www.mindstick.com/forum/12949/how-to-validate-if-a-datetime-field-is-not-null-empty) 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!

## Replies

### Reply by Pravesh Singh

Hi Samuel,

You can [convert](https://www.mindstick.com/forum/2093/configurationmanager-appsettings-convert-n-to-n-why) the view model to Json object most cases followed with MVC

In this case you need not convert the json data in your view.

## You can use something like this code

```
var date = Date;var viewModel = new ViewModel();var serializer = new JavaScriptSerializer();viewModel.JsonData = serializer.Serialize(data);return View("viewname", viewModel);
```

and then in view you use

<%= Model.JsonData %>


---

Original Source: https://www.mindstick.com/forum/2015/string-to-object-mvc-model-binding

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
