frankie
frankie

Reputation: 728

Pass data from different controllers to one view

I am developping ASP.NET MVC5 SPA. I have file called HomeController.cs and it's view called _Home.cshtml.

I'd like to implement current logic: when user enter on _Home view application connects to repository and get some data, then fill that data on view into <li></li> element.

Here my full HomeController.cs class

public class HomeController : Controller
{


    public ActionResult Index()
    {
        //I am not sure if this code should be in Index method

        //Assume, that data is taken from repository, but it's no matter
        var contactsListModels = new List<ContactListModel>()
        {
            new ContactListModel() {FirstName = "Fred", LastName = "Perry"},
            new ContactListModel() {FirstName = "Jon", LastName = "Skeet"}
        };

        //In some way need to pass it into _Home.cshtml

        return View();
    }

}

And part of _Home.css

<div class="col-md-3">
    <div class="col-contacts">
        <div class="col-contacts-textbox-and-contacts">
            <input type="text" class="form-control" />

            <!-- Manually added data, but it has to be automatically passed from repository-->
            <ul>
                <li>Jon Skeet</li>
                <li>Fred Perry</li>
            </ul>

        </div>
    </div>
</div>

Upvotes: 0

Views: 31

Answers (1)

frankie
frankie

Reputation: 728

I am already found excellent solution for my question on CodeProject. It could be accomlished in multiple ways.

Upvotes: 1

Related Questions