Getting the caller name from inside of the view

104 views Asked by At

I'm invoking my view using

@Html.EditorFor(m => Model.FileListBefore)

I would like to get the 'FileListBefore' name from the inside of the view. How can I do that?

EDIT (more info):

'EditorFor(m => Model.FileListBefore)' uses my own sub-view. In that sub-view I want to retrieve the name of property which invoked this view.

Why? Because I'm calling

@Html.EditorFor(m => Model.FileListBefore)

@Html.EditorFor(m => Model.FileListAfter)

'FileListBefore' and 'FileListAfter' are the same type 'FileList' (my own class) and they call the same sub-view. I want to get the calling names ('FileListBefore' and 'FileListAfter) inside sub view because I want to identify them and add it do div 'id' value.

1

There are 1 answers

0
Soumya On

The question is unclear to me. However, to simply see the property name which invoked the view, you can add Debug.WriteLine("Inside <property name>"); inside every property so it gets printed in the Output Console of Visual Studio. If you want to print the name in a sub-view, you can add <p>@ViewBag.PropertyName</p> in the sub-view and add ViewBag.PropertyName="<property name>"; inside every property.

By every property I imply all those properties that could call this View.