0

I have created tabs using kendo tabs in below format. Now I want to create tabs inside the div and show partial views for each tab by calling a controller action and pass two parameters to that controller action that returns the partial view with its model data. I have checked so many solutions but could get a right solution which would solve my requirement. Can anyone help.

<ul>
    @foreach(var item in model)
        {
            <li>
                @item.DocumentVersion
            </li>
        }
</ul>
@foreach(var Document in model)
        {
            <div>
                <p>
                    @Document.Details
                </p>
                </br>
                <span>
                    @Document.File
                </span>
            </div>
        }
7
  • So do that...and post that if it does not work. i.e. calling a controller action and pass two parameters to that controller action that returns the partial view with its model data. - search "Partial View MVC" I would think Commented Apr 7, 2017 at 21:00
  • @MarkSchultheissam hello .. its not about calling the controller action and passing parameters.I need to achieve tat in my tab view. I dont know how I can achieve that and landed up here. Commented Apr 7, 2017 at 21:04
  • stackoverflow.com/questions/16656073/… Commented Apr 7, 2017 at 21:05
  • And HERE for how to pass parameters stackoverflow.com/questions/6549541/… Commented Apr 7, 2017 at 21:07
  • I know doing that i.e calling controller action and returning partial view. But I dont know how to do it to render the view in the tabs content Commented Apr 7, 2017 at 21:09

1 Answer 1

0

Render the partial IN the view (simplistic example)

<div>
@{Html.RenderPartial("MyPartialViewName",
    new { firstName = model.FirstName, lastName = model.LastName});
}
</div>

<div>
@{Html.RenderPartial("MyPartialViewName","MyController",
    new { firstName = model.FirstName, lastName = model.LastName});
}
</div>

Create parameter view action

[ChildActionOnly]
public ActionResult MyPartialViewName(string firstName, string lastName)
{
// create model here...
 var model = repository.GetThingByParameter(firstName,lastName);
 var partialViewModel = new PartialViewModel(model);
 return PartialView(mypartialViewModel); 
}

Example view code:

 <p>
    @model.something
 </p>
 </br>
 <span>
    @model.otherthing
 </span>

OR do all markup in the partial view:

<div>
    <p>
        @model.something
    </p>
    </br>
    <span>@model.otherthing</span>
</div>

Current page:

@foreach(var Document in model)
{
    @{Html.RenderPartial("MyPartialViewName",
        new { firstName = model.FirstName, lastName = model.LastName});
    }
}

Note you can also pass the model part as the Document:

 @foreach(var Document in model)
 {
    @{Html.RenderPartial("MyPartialViewName",Document);
 }

And the partial view: (no parameters passed here...just the model)

@model YourApp.Model.Document
<div>
  <p>
        @Model.Details
   </p>
   </br>
   <span>@Model.File</span>
</div>
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. I will try the above code tomo morning. I hope it works.
This code works for calling the partial view directly from inside the div. But i want to call the controller action, which is not happening.
I edited the answer (see near the top of example to specify controller - it should call the action named within that controller. It should call that controller, set a debug in it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.