'Is it bad to have methods in a model?

In ASP.NET MVC I'm thinking to implement a method that converts data to JSON. However, I'm not sure where to add this method. Should I add it in Controller, service class, or Model? So, for example, let's say I have a model named book and a controller named Library.

public class Book
{
    public string Name { get; set; }
    public string Json { get; set; }
}

public class Library: Controller
{
    public ActionResult Book(string bookName)
    {
        return View();
    }
}

Should I add a private method like JsonConverter(object jsonToConvert) in Book class and call it in the constructor of Book? So, a user will pass an object to be converted to Book class, and then when instantiated it will be converted to Json and assigned to Book.Json.

Is adding methods in a model a bad practice? Is it better to add a service class that has JsonConverter and do the conversion in the controller?

So, like

public class Library: Controller
{
    public ActionResult Book(string bookName)
    {
        var book = GetBook(bookName)
        var json = Service.ConvertJson(book.object)
        return View(book, json);
    }
}

To sum up my question: is it bad practice to add private methods in a model and manipulate data format? The reason why I don't want to do the conversion in the controller is that I think it is a bad practice to convert data format in a class as the data layer is Model. Am I wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source