JP Hochbaum
JP Hochbaum

Reputation: 647

"The view or its master was not found error." But my intent is to not look for the view

I obviously have this coded wrong. My "addmenuItems" action method is not supposed to return an "addmenuItems" view, which should be apparent in my code below.

I am trying to return the view "follower", so why is it looking for "addmenuitems"?

public ActionResult AddMenuItems(List<int> MenuItemID, int? FollowerID)
{
    Follower follower = new Follower();
    if (FollowerID == null)
    {
        return View(follower);
    }
    else
    {
        follower = db.Followers.Find(FollowerID);
        follower.MenuItems.Where(m => !MenuItemID
            .Contains(m.MenuItemID))
            .ToList()
            .ForEach(m => follower.MenuItems.Remove(m));
        var existingMenuItemIds = follower.MenuItems.Select(m => m.MenuItemID).ToList();
        db.MenuItems.Where(m => MenuItemID.Except(existingMenuItemIds)
            .Contains(m.MenuItemID))
            .ToList()
            .ForEach(m => follower.MenuItems.Add(m));
        return View(follower);   
    }
}

And below here is the View:

@using (Html.BeginForm("AddMenuItems", "Merchants", FormMethod.Post))
{
    <div class="form-group">
        <div class="col-lg-offset-2 col-lg-1">
            <button type="submit" class="btn btn-default">Follow these Menu Items</button>
        </div>
    </div>
}

Upvotes: 0

Views: 174

Answers (1)

user3559349
user3559349

Reputation:

By default, return View(model) will display the view with the same name as your action method. To specify a different view, the it needs to be

return View("follower", follower);

where the first parameter is the name of the view.

Upvotes: 1

Related Questions