How can I know in the controller which partial view made a callback

ilay zeidman

I have two partial views that has the same model, I am using devexpress callbacks. My question is if I can know in my controller function which partial view made the callback and then render it? Or I need to duplicate the function and just render in each function the correct partial view?

Michael

Your view returns to you only that you pass into it. So, you should pass your view-name into the hidden field container, as an example, and then read this value from the server side. Someone already answered how to pass view name, I will try to extend this answer.

First of all, you need to create some view-path parsing extension

public static class IViewExtensions
{
    public static string GetViewName(this IView view)
    {
        string viewUrl = String.Empty;
        if (view is BuildManagerCompiledView)
        {
            viewUrl = ((BuildManagerCompiledView)view).ViewPath;
        }
        else
        {
            throw new InvalidOperationException("Buld manager is not defined!");
        }

        string viewFileName = viewUrl.Substring(viewUrl.LastIndexOf('/'));
        string viewFileNameWithoutExtension = Path.GetFileNameWithoutExtension(viewFileName);
        return (viewFileNameWithoutExtension);
    }
}

Then pass your each view-names into the form container

@using ViewExtensionNamespace;
<input type="hidden" id="ViewName" name="ViewName" value="@Html.ViewContext.View.GetViewName()" />

And read it from the server side

 name = Request.Params["ViewName"];

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I know which view is associated with which controller?

From Dev

How can I pass a variable to a partial which is shared with another controller?

From Dev

How exactly does a .net MVC controller know which View() to return?

From Dev

How to know which was my previous tab bar view controller in iOS?

From Dev

How can I know which item in a handlebars each loop triggered a function in my Ember controller?

From Dev

How can I know which item in a handlebars each loop triggered a function in my Ember controller?

From Dev

Controller can not find partial view

From Dev

How do I check which controller is used to render a partial in Rails?

From Dev

how can i know which button is cliked

From Dev

how to know on which button user made click?

From Dev

How can I tell which IDE an Android project was made with?

From Dev

How can I tell which IDE an Android project was made with?

From Dev

How can I refresh partial view and the main view at the same time?

From Dev

How can I refresh just a Partial View in its View?

From Dev

How can I refresh partial view and the main view at the same time?

From Dev

How can I refresh just a Partial View in its View?

From Dev

How can I know which folders are created by which program?

From Dev

How can I know which folders are created by which program?

From Dev

How can view controllers in a tab controller know when it is being unwinded?

From Dev

How can I trigger a function on a div returned after an Ajax form is submitted by a partial view returned by my controller action?

From Dev

How to Return partial view of another controller by controller?

From Dev

How can I reuse a controller for multiple partial views?

From Dev

How can I reuse a controller for multiple partial views?

From Dev

How do I know what dependencies I can inject into a controller?

From Dev

How can I override the method of view in Controller?

From Dev

How can i know which link i clicked in an HTML

From Dev

How to know which call the current callback is for?

From Dev

How can I refresh a partial view on the main index page on a submit from a separate partial view modal

From Dev

How can I receive form data in callback with post value in controller?

Related Related

  1. 1

    How do I know which view is associated with which controller?

  2. 2

    How can I pass a variable to a partial which is shared with another controller?

  3. 3

    How exactly does a .net MVC controller know which View() to return?

  4. 4

    How to know which was my previous tab bar view controller in iOS?

  5. 5

    How can I know which item in a handlebars each loop triggered a function in my Ember controller?

  6. 6

    How can I know which item in a handlebars each loop triggered a function in my Ember controller?

  7. 7

    Controller can not find partial view

  8. 8

    How do I check which controller is used to render a partial in Rails?

  9. 9

    how can i know which button is cliked

  10. 10

    how to know on which button user made click?

  11. 11

    How can I tell which IDE an Android project was made with?

  12. 12

    How can I tell which IDE an Android project was made with?

  13. 13

    How can I refresh partial view and the main view at the same time?

  14. 14

    How can I refresh just a Partial View in its View?

  15. 15

    How can I refresh partial view and the main view at the same time?

  16. 16

    How can I refresh just a Partial View in its View?

  17. 17

    How can I know which folders are created by which program?

  18. 18

    How can I know which folders are created by which program?

  19. 19

    How can view controllers in a tab controller know when it is being unwinded?

  20. 20

    How can I trigger a function on a div returned after an Ajax form is submitted by a partial view returned by my controller action?

  21. 21

    How to Return partial view of another controller by controller?

  22. 22

    How can I reuse a controller for multiple partial views?

  23. 23

    How can I reuse a controller for multiple partial views?

  24. 24

    How do I know what dependencies I can inject into a controller?

  25. 25

    How can I override the method of view in Controller?

  26. 26

    How can i know which link i clicked in an HTML

  27. 27

    How to know which call the current callback is for?

  28. 28

    How can I refresh a partial view on the main index page on a submit from a separate partial view modal

  29. 29

    How can I receive form data in callback with post value in controller?

HotTag

Archive