在asp.net核心剃须刀页面上使用局部视图 [英] using partial view on asp.net core razor pages

查看:35
本文介绍了在asp.net核心剃须刀页面上使用局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个在asp.net core 2剃须刀页面上运行的项目.我需要一种解决方案来将部分视图或组件加载到RAZOR页面中,并且还可以发送come对象(某些类模型或基本字符串).

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);
}

这是我里面的局部视图

<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>

向下是局部视图模型

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

推荐答案

找到了解决方案.将部分剃刀视图添加到项目VS剃刀局部视图模板时,请在局部视图CSHTML的顶部添加 @page .您需要将其删除才能正常工作.

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.

这是旧的部分视图CSHTML文件

this is the old partial view CSHTML file

@page
@model Project.Model

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

和新的:

@model Project.Model

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

这篇关于在asp.net核心剃须刀页面上使用局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆