1

I have a controller named DaftarController that calls Index view and fill it with mode.l

DaftarController:

    public ActionResult Index()
    {
        List<EventRecord> li = ws.GetEvents().ToList();
        var ura = li;
        return View(ura);
    }

It shows perfectly, but I want partial view inside my Index view.

@Html.Partial("~/Views/Daftar/_Deleted.cshtml");

So I add this in my DaftarController:

    public ActionResult _Deleted()
    {
        List<DeletedRecord> li = ws.GetDeleteds().ToList();
        var ura = li;
        return View(ura);
    }

But it gives error. I'm still confuse how to show partial view with model in it?

2 Answers 2

3

If you want to call an action even though the action will return a partial view, you should use.

@Html.Action("_Deleted", "Daftar") // Assume _Deleted is inside DaftarController

This will call the action then returns the view, and in your _Deleted action, you need to return it with PartialView method otherwise the layout will be included as the result.

public ActionResult _Deleted()
{
    List<DeletedRecord> li = ws.GetDeleteds().ToList();
    var ura = li;
    return PartialView(ura); // Not View(ura)
}

If you directly call the@Html.PartialView, that means you directly render the view without going to the action.

Sign up to request clarification or add additional context in comments.

Comments

2

When you are defining a partial view to use in a razor view, you do not define the path with the file extension.

So for your partial, it would be:

@Html.Partial("~/Views/Daftar/_Deleted");

1 Comment

Nope, without .cshtml extension it return error View not found

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.