Visual Studio CS7036使用www.example.com核心剃刀页C#中Pages文件夹中的Partial.cshtml文件时出现错误消息asp.net

pes8fvy9  于 2022-12-14  发布在  C#
关注(0)|答案(2)|浏览(97)

我正在Asp.netVisual Studio Enterprise 2019中使用www.example.com核心Razor Pages C#构建一个应用程序。我想向现有应用程序添加日历应用程序。我在Pages文件夹下的Calendars文件夹中添加了一个名为CRUDPartial.cshtml的表单。
但是,在第一行代码中会抛出一个错误,并且BeginForm以红色突出显示:

@using (Html.BeginForm(Model.ActionName, Paths.INDEX_PATH, new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
    @Html.AntiForgeryToken()

    <div class="well bs-component custom-background2">
        <div class="row" style="display:none;">
            <div class="form-group">
                <div class="col-md-10 col-md-pull-1">
                    @Html.HiddenFor(m => m.Event_id, new { @readonly = "readonly", placeholder = Html.DisplayNameFor(m => m.Event_id), @class = "form-control" })
                    @Html.HiddenFor(m => m.IsView, new { @readonly = "readonly", placeholder = Html.DisplayNameFor(m => m.IsView), @class = "form-control" })
                    @Html.HiddenFor(m => m.ButtonText, new { @readonly = "readonly", placeholder = Html.DisplayNameFor(m => m.ButtonText), @class = "form-control" })
                    @Html.HiddenFor(m => m.StartDateTime, new { id = "startDateVal", @readonly = "readonly", placeholder = Html.DisplayNameFor(m => m.StartDateTime), @class = "form-control" })
                    @Html.HiddenFor(m => m.EndDateTime, new { id = "endDateVal", @readonly = "readonly", placeholder = Html.DisplayNameFor(m => m.EndDateTime), @class = "form-control" })
                </div>
            </div>
        </div>

错误消息为:
CS 7036:-没有给定与“IHtmlHelper.BeginForm(string,string,object,FormMethod,bool?,object)”所需形参“htmlAttributes”对应的实参
当我建置方案时,建置的输出会在下列位置掷回错误消息:-完成建置项目“ProjectName.csproj”--失败。
随后会显示更多错误消息:- CS 0246-找不到类型或命名空间名称“PrivacyModel”(是否缺少using指令或程序集引用?)
错误消息出现在以下代码行:

public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<PrivacyModel> Html { get; private set; }
public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<PrivacyModel> ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<PrivacyModel>)PageContext?.ViewData;

任何帮助解决这些问题将不胜感激。

agxfikkp

agxfikkp1#

Html.BeginForm帮助器不应在Razor Pages中使用。它旨在支持向MVC控制器和操作提交表单。您应改用form tag helper
但您的错误消息的原因是.NET核心IHtmlHelper.BeginForm方法expects 6 arguments。您只提供了5。

bis0qfac

bis0qfac2#

MVC示例

@using (Html.BeginForm("ActionName", "ControllerName",
                new { area = "AreaName" }, FormMethod.Post, new
                {
                    @class = "col-6"
                }))
                    {
                    }

Core示例

@using (Html.BeginForm("ActionName", "ControllerName",
                    new { area = "AreaName" }, FormMethod.Post,null, new
                    {
                        @class = "col-6"
                    }))
                        {
                        }

相关问题