Last active
August 29, 2015 14:01
-
-
Save hazzik/b9c35d8ff86ef23d834d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@{ | |
var data = new RouteValueDictionary(ViewData); | |
object action; | |
ViewData.ModelMetadata.AdditionalValues.TryGetValue("action", out action); | |
object controller; | |
ViewData.ModelMetadata.AdditionalValues.TryGetValue("controller", out controller); | |
object area; | |
ViewData.ModelMetadata.AdditionalValues.TryGetValue("area", out area); | |
if (!string.IsNullOrEmpty((string) area)) | |
{ | |
data["area"] = area; | |
} | |
if (!string.IsNullOrEmpty((string) controller)) | |
{ | |
Html.RenderAction((string) action, (string) controller, data); | |
} | |
else | |
{ | |
Html.RenderAction((string)action, data); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RenderActionAttribute : Attribute, IMetadataAware | |
{ | |
public RenderActionAttribute([AspMvcAction] string action) | |
{ | |
Action = action; | |
} | |
public RenderActionAttribute([AspMvcAction] string action, [AspMvcController] string controller) | |
{ | |
Action = action; | |
Controller = controller; | |
} | |
public RenderActionAttribute([AspMvcAction] string action, [AspMvcController] string controller, [AspMvcController] string area) | |
{ | |
Action = action; | |
Controller = controller; | |
Area = area; | |
} | |
public string Action { get; set; } | |
public string Controller { get; set; } | |
public string Area { get; set; } | |
public void OnMetadataCreated(ModelMetadata metadata) | |
{ | |
if (!string.IsNullOrWhiteSpace(Action)) | |
metadata.AdditionalValues["action"] = Action; | |
if (!string.IsNullOrWhiteSpace(Controller)) | |
metadata.AdditionalValues["controller"] = Controller; | |
if (!string.IsNullOrWhiteSpace(Area)) | |
metadata.AdditionalValues["area"] = Area; | |
metadata.TemplateHint = "RenderAction"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment