---
title: "refactor Html.LabelFor, EditorFor, ValidationMessageFor into partial view"  
description: "refactor Html.LabelFor, EditorFor, ValidationMessageFor into partial view"  
author: "Manoj Bhatt"  
published: 2013-02-04  
updated: 2013-02-04  
canonical: https://www.mindstick.com/forum/573/refactor-html-labelfor-editorfor-validationmessagefor-into-partial-view  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 1 minute  

---

# refactor Html.LabelFor, EditorFor, ValidationMessageFor into partial view

Hi Everyone!

I want to refactor view form [code to avoid](https://www.mindstick.com/forum/33394/under-what-condition-could-the-code-sample-below-crash-your-application-how-would-you-modify-the-code-to-avoid-this-potential-problem) copyPaste. But it's not working. [Razor](https://www.mindstick.com/articles/12002/asp-dot-net-mvc5-razor-with-jquery) don't allow to write

@[model](https://yourviews.mindstick.com/view/81334/america-is-reopening-after-corona-lockdown-but-on-swedish-model) System.Linq.Expressions.[Expression](https://www.mindstick.com/articles/1861/sqlite-expressions)<Func<TModel, TValue>> expression\
and

@[Html.Partial](https://www.mindstick.com/forum/2318/what-is-the-difference-between-html-partial-and-html-renderpartial-and-html-action-and-html-renderaction)("Item", model => model.EmpName)\
Old code, that working:

<tr>\
<td [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp)="[editor](https://www.mindstick.com/forum/78/how-avoid-the-html-tag-and-remove-the-formating-of-copy-in-ajax-editor)-[label](https://www.mindstick.com/articles/12835/print-label-tracking-how-do-these-features-make-auspost-woocommerce-plugin-better)" [style](https://www.mindstick.com/articles/126300/apa-citation-style-get-to-know-about-it-for-your-next-assignment)="border: 0;">\
@Html.LabelFor(model=>model.EmpName)\
</td>\
<td class="editor-field" style="border: 0">\
@Html.EditorFor(model=>model.EmpName)\
@Html.ValidationMessageFor(model=>model.EmpName)\
</td>\
</tr>\
<tr>\
<td class="editor-label" style="border: 0;">\
@Html.LabelFor(model=>model.Email)\
</td>\
<td class="editor-field" style="border: 0;">\
@Html.EditorFor(model=>model.Email)\
@Html.ValidationMessageFor(model=>model.Email)\
</td>\
</tr>\
After refactoring not working:

Item.cshtml:

@model System.Linq.Expressions.Expression<Func<TModel, TValue>> expression\
<tr>\
<td class="editor-label" style="border: 0;">\
@Html.LabelFor(expression)\
</td>\
<td class="editor-field" style="border: 0">\
@Html.EditorFor(expression)\
@Html.ValidationMessageFor(expression)\
</td>\
</tr>\
}\
New code:

@Html.Partial("Item", model => model.EmpName)\
@Html.Partial("Item", model => model.Email)

How to make it work?

Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)

## Replies

### Reply by AVADHESH PATEL

Hi Manoj Bhatt!

You can try this way

@Html.MyEditFor(m => m.Name)

Partial view not support lambda express, so you try this way

@Html.Partial("Item", Model.EmpName)


---

Original Source: https://www.mindstick.com/forum/573/refactor-html-labelfor-editorfor-validationmessagefor-into-partial-view

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
