---
title: "Correct way to use AutoMapper in ASP.Net MVC"  
description: "Correct way to use AutoMapper in ASP.Net MVC"  
author: "Anonymous User"  
published: 2013-05-10  
updated: 2013-05-10  
canonical: https://www.mindstick.com/forum/856/correct-way-to-use-automapper-in-asp-dot-net-mvc  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Correct way to use AutoMapper in ASP.Net MVC

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances)!\
I'm trying to tart using ViewModels - but I'm [having trouble](https://answers.mindstick.com/qa/50524/how-to-fix-iphone-8-that-s-overheating-and-having-trouble-turning-on) with this POST not validating - the values in the model are shown in the Watch part below the code:\
ModelStats.IsValid = false\
My ItemViewModel is:\
public class ItemViewModel { public int ItemId { get; set; } [Display(Name = "Item")] public [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) ItemName { get; set; } [Display(Name = "Description")] public string Description { get; set; } [Display(Name = "Price")] public double UnitPrice { get; set; } [Range(0.00, 100, ErrorMessage = "VAT must be a % between 0 and 100")] public [decimal](https://www.mindstick.com/forum/34709/please-write-a-program-for-decimal-to-binary-conversion-in-c-sharp) VAT { get; set; } [[Required](https://www.mindstick.com/forum/160269/what-is-required-data-annotation-how-does-it-affect-model-validation)] public string [UserName](https://www.mindstick.com/forum/12798/there-is-no-viewdata-item-of-type-ienumerable-selectlistitem-that-has-the-key-username) { get; set; } }I'm sure it will be something [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) - but I've just been looking at it so long, I can't figure out what I'm [doing wrong](https://answers.mindstick.com/qa/36736/what-are-indians-doing-wrong-on-whatsapp). Can [anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) please advise?\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Tanuj!\
In order to Use AutoMapper\
First, Create a map, such as\
Mapper.CreateMap<Item, ItemViewModel>();\
And then map\
var itemModel = Mapper.Map<Item, ItemViewModel>(model);


---

Original Source: https://www.mindstick.com/forum/856/correct-way-to-use-automapper-in-asp-dot-net-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
