3

I am developing a project that runs on asp.net core 2 razor pages. I need a solution to load a partial view or component to in a RAZOR pages and also I could send come object (some class model or basic string).

this is detail pages which I want load partial view into. Using this code :

@{
    await Html.RenderPartialAsync("Shared/Partial/DeleteModal", Model.DeleteModalModel);
}

this is my partial view inside

<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header bg-red">
                <h4 class="modal-title" id="defaultModalLabel">DİKKAT KAYIT SİLİNECEKTİR !</h4>
            </div>
            <div class="modal-body">                
            </div>
            <div class="modal-footer">
                <input type="submit" asp-page-handler="Delete" class="btn bg-red m-t-15 waves-effect" value="Sil" data-toggle="modal" data-target="#deleteModal" />
                <button type="button" class="btn bg-indigo m-t-15 waves-effect" data-dismiss="modal">@Html.DisplayNameFor(model => Model.ViewModel.Buttons.Close)</button>
            </div>
        </div>
    </div>
</div>

down is the partial view model

using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Q.Presentation.System.Razor.Pages.Shared.Partial
{
    public class DeleteModalModel : PageModel
    {
        public string Message { get; set; }
    }
}

I want the set Message property from DETAIL page and want to show up on partial view which I want to load into DETAIL razor pages

1 Answer 1

5

found a solution. when you add a partial razor view to project VS razor partial view template add @page top of the partial view CSHTML. You need to remove that to work properly.

this is the old partial view CSHTML file

@page
@model Project.Model

<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog">
......

and the new one :

@model Project.Model

<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog">
........
Sign up to request clarification or add additional context in comments.

1 Comment

I just found my problem that removing @page on top then it works. I just wonder why we have to do that? Can you explain to me, please?

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.