title: Retrieve the current view name in ASP.NET MVC?
body: <p>I have a partial view (control) that's used across several view pages, and I need to pass the name of the current view back to the controller - so if there's e.g. validation errors, I can re-draw the original view.</p>
  
  <p>A workaround way to do it would be (in the controller methods)</p>
  
  <pre><code>var viewName = "Details"; // or whatever
  ViewData["viewName"] = viewName;
  return(View(viewName, customer));
  </code></pre>
  
  <p>and then in the partial itself, render it as</p>
  
  <pre><code>&lt;input type="hidden" name="viewName" 
      value="&lt;%=Html.Encode(ViewData["viewName"])%&gt;" /&gt;
  </code></pre>
  
  <p>Question is - is there some property or syntax I can use to retrieve this directly instead of setting it from the controller? I've tried the obvious:</p>
  
  <pre><code>&lt;input type="hidden" name="viewName" 
      value="&lt;%=Html.Encode(this.Name)%&gt;" /&gt;
  </code></pre>
  
  <p>but this doesn't work. What am I missing here?</p>
  
  <p>Thanks.</p>