hi.
i want to render specific action in other controller in dnn.
how can i do that?
in my view i write this code:
Html.RenderPartial is just for render partial in same controller.but not work for render action in other controller
Html.RenderPartial("N_Notary/Index");
where N_Notary is my controller and index is my action.
Url.Action
yes it is mvc module.
URL.Action just create url of action for me.not render the action
what i want to do is this:based on setting of module i need to show specific action
var DefaultStartAction = Dnn.ModuleContext.Configuration.ModuleSettings.GetValueOrDefault("NotaryStartAction", ""); if (!string.IsNullOrEmpty(DefaultStartAction)) {
Html.RenderPartial("N_Notary/Index"); } else { Html.RenderPartial("N_Notary/Index2"); }
Thank you for answering my questions.
yes this is work for me:
Html.RenderPartial("~/DesktopModules/MVC/Notary/Views/Home/Index2.cshtml");
---------------------------
Another way to useAnother way to useAnother way to useanother way to do that instead of coding in view is using controller like this(based on your answer):
var defaultStartAction = ModuleContext.Configuration.ModuleSettings.GetValueOrDefault("NotaryStartAction", ""); var defaultStartController = ModuleContext.Configuration.ModuleSettings.GetValueOrDefault("NotaryStartController", ""); if (!string.IsNullOrEmpty(defaultStartAction) && !string.IsNullOrEmpty(defaultStartController)) { return Redirect(defaultStartAction, defaultStartController); } else { return Redirect("Index2", "Home"); }
-------
but the Redirect not worked correctly and i create class drived from DnnController and add new Redirect method to it like this:
public class MyDnnController : DnnController {
protected RedirectResult Redirect(string actionName, string controllerName, RouteValueDictionary routeValues = null) {
if (routeValues == null) { routeValues = new RouteValueDictionary(); } routeValues["controller"] = controllerName; routeValues["action"] = actionName; return Redirect(ModuleRoutingProvider.Instance().GenerateUrl(routeValues,this. ModuleContext));
}
and then change inheritance of my Homecontroller to use "MyDnnController"
public class HomeController : MyDnnController
and this worked for me.
thank you again.
No problem! Glad you got it working.
Routing in the MVC modules sometimes is weird and it "should" work, but I sometimes need to use fully qualified view paths. The .cshtml file lookup should be able to find your .cshtml with just a partial.
Another note I wanted to share for your Controller code. You really should look at the "Url.Action" capabilities as it makes Redirecting to other controllers super simple.
These Forums are dedicated to the discussion of DNN Platform.
For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:
Awesome! Simply post in the forums using the link below and we'll get you started.