none
How to add a partial view without open a new tab in mvc RRS feed

  • Question

  • Hi,

    I have a table where first column is a link label with some ID. When I click that label I add a new tab for the table where I have to load a partial view with details based on the ID that I clicked. Problem is if I used a Action link and return the Partial view will redirect me to another page. Ca anyone point me the right direction on how to do this?

    Controler code.

     [HttpGet]
            public PartialViewResult Test(string caseReference)
            {
                // Get attachments
                // HERE NEED API TO GET CASE ATTACHMENTS; pass parameter case reference.
                Attachments caseAttachments = new Attachments()
                {
                    AttachmentsName = new List<string>() { "Bogdan.docx", "Daniel.docx", "Popescu.docx" },
                    AttachmentsDate = new List<string>() { "01.01.2020", "02.02.0202", "03.03.2011" }
                };
    
                // Here we need api to get case events; pass parameter case reference.
                Events events = new Events()
                {
                    EventsDescription = new List<string>() { "Bogdan.docx", "Daniel.docx", "Popescu.docx" },
                    EventsDate = new List<string>() { "01.01.2020", "02.02.0202", "03.03.2011" }
                };
    
                // Create object with case details for the new tab.
                CaseDetails caseDetails = new CaseDetails()
                {
                    OfficialNumber = caseReference,
                    CountryCode = caseReference,
                    CaseType = caseReference,
                    Status = caseReference,
                    Attachments = caseAttachments,
                    Events = events
                };
    
                return PartialView("_TabContent", caseDetails);
            }


    Home.cshtml Here I call the Controler method 

    <td class="nobr" data-label="Ihr Zeichen Unser Zeichen"><a onclick="createTab('@item.CaseReference');"@Html.ActionLink("HomeController","Test", new {caseReference = @item.CaseReference })>@item.CaseReference</a></td>

    At the end of Home.cshtml i use 

    @Html.Partial("_TabContent")

    The ideea is that when I press the Item in label is to open a new tab above the table with information based on that id. Maybe I got it all wrong.

    Thanks.

    Friday, February 21, 2020 12:59 PM

All replies

  • Hi Bogdan-Sorin,

    Welcome to MSDN forum.

    What is your project type? Please share us some details so that we can help move this thread to a suitable forum.

    In addition, according to your description, I suppose you don’t want to redirect to another page when clicking the link. You could use event.preventDefault(); to prevent the default browser behavior. Please have a look at the similar issue and hope it helps.

    Have a nice day.

    Best regards,

    Anna


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, February 24, 2020 10:57 AM
  • Hi Anna,

    The project is ASP.NET MVC.


    Monday, February 24, 2020 11:08 AM
  • Hi Bogdan-Sorin, 

    Thanks for your feedback and sorry for my delay reply.

    If you want to load PartialView with using jquery Ajax, you could think about using .load().

    In addition, because this issue is about code development and our forum is to discuss about .NET Framework Setup and Servicing issue. So I suggest you could ask the asp.net-mvc forum for a better help.

    If there is anythng else we can do for you, please feel free to post in the forum.

    Best regards,

    Anna


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Tuesday, February 25, 2020 11:39 AM
  • This cannot be done from within the controller itself, but rather from your View. As I see it, you have two options:

    1. Decorate your link with the "_blank" attribute (examples using HTML helper and straight HMTL syntax)

      • @Html.ActionLink("linkText", "Action", new {controller="Controller"}, new {target="_blank"})
      • <a href="@Url.Action("Action", "Controller")" target="_blank">Link Text</a>
    2. Use Javascript to open a new window

      window.open("Link URL")

    I hope this helps!

    Regards

    Abigail | Apps4Rent

    Tuesday, February 25, 2020 11:59 AM