Products

Solutions

Resources

Partners

Community

Blog

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Open Core Testi...Open Core Testi...DNN 8 -> MVC -> Call controller action from viewDNN 8 -> MVC -> Call controller action from view
Previous
 
Next
New Post
11/10/2015 9:30 PM
 

Hi all,

DNN 8 is working fine, I got nearly all features working, e.g. partials and partial views. Now I came across with a problem I can't solve by myself. I wanna call a controller action directly from a view. Problem is: I get an exception telling me that there are no routes that would match. What I did was: Initialize a new instance of System.Web.Mvc.HtmlHelper like new HtmlHelper<T>(base.ViewContext, this, base.Html.RouteCollection), in the overridden System.Web.Mvc.WebViewPage.InitHelpers() method, then calling base.HtmlHelper.Action("[METHOD]", "[CONTROLLER]") from the view to invoke the controller's action. Is there anybody out there who knows how to achieve the goal?

Tobias

 
New Post
11/12/2015 3:04 PM
 

Since DNN is taking care of routing, you won't be able to use a stock HtmlHelper to create the right URL that you want.  That said, DNN had created its own versions of the Html and Url helpers that you can use in your view.  See the Action method of the DnnUrlHelper class for your options.  You should be able to call Url.Action("Method") from your view (or Url.Action("Method", "Controller") if it's connected to a different controller).

Hope it helps!


Brian Dukes
Engage Software
St. Louis, MO
866-907-4002
DNN partner specializing in custom, enterprise DNN development.
 
New Post
11/12/2015 3:14 PM
 

Hi Brian,

I know that DNN replaces the HTML helper by its own, but i use the default one in addition to get partials working. Url.Action prints the client URL of the action to the view as String, I use this to configure client side partial rendering (https://dnntracker.atlassian.net/brow...). The question is, is there a way to invoke a controller method before the rendered HTML get sent to the client?

Tobi

 
New Post
9/11/2018 7:05 PM
 
I am having a similar issue.

This is my image element:

Event

But the .Action is returning the wrong URL if the module is on a page other than the Home page. The action is return a url of "/Home/..."

I have a controller/action that renders an images and sends to the client/image element. This works fine if the module is on the home page.
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Open Core Testi...Open Core Testi...DNN 8 -> MVC -> Call controller action from viewDNN 8 -> MVC -> Call controller action from view


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out