locked
Load partial view in anchor RRS feed

  • Question

  • User1230819687 posted

    Hello!

    I'm fairly new to asp.net mvc and would need some advice in how to load a partial view in anchor link.

    I have a view as a partial (maybe this is not the right way to do it?)
    To load views i do : <asp-area="Public" asp-controller="Payment" asp-action="Index">, is there any taghelper to add a partial in the same way? 
    E.g. asp-partial="PaymentPartial"

    Wednesday, March 20, 2019 1:57 PM

All replies

  • User-474980206 posted
    Links (anchors) cause the browser to replace the current page with the results of the links get request. If url returns a partial, then the page will be replaced with just the partial.

    If you wanted to just change part of the page without a reload, then this is done with JavaScript and Ajax.
    Wednesday, March 20, 2019 2:14 PM
  • User1230819687 posted

    I want to replace the current page, any suggestions in how? 

    Thank you!

    Wednesday, March 20, 2019 2:35 PM
  • User-474980206 posted

    when an action returns a partial view, this just set the layout to null, so the returned html does not include the layout html, just the views html (also any section in the view will not be included, as the layout is not called).

    if you want to replace the page, normally the link would be to an action that returned the view you want (while this view may include partials).

     

    Wednesday, March 20, 2019 3:45 PM
  • User1230819687 posted

    when an action returns a partial view, this just set the layout to null, so the returned html does not include the layout html, just the views html (also any section in the view will not be included, as the layout is not called).

    if you want to replace the page, normally the link would be to an action that returned the view you want (while this view may include partials).

    Okey! Yeah I figure I shouldn't have views as partials, solved it! Thank you

    Wednesday, March 20, 2019 3:54 PM