为什么我的Razor Page方法没有被调用? [英] Why do my Razor Page methods not get called?

查看:112
本文介绍了为什么我的Razor Page方法没有被调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使Razor Pages正常工作.它将显示索引"页面,仅此而已.该页面上没有任何链接,也不会显示任何数据.编译器将完全忽略所有辅助方法,甚至不会以其他颜色突出显示它们.

I cannot get Razor Pages to work. It will display the Index page and thats it. No links work on the page and no data will display. All Helper Methods are completely ignored by the compiler, it will not even highlight them in a different colour.

页面加载时,它将调用Get函数,并显示页面,但是视图上的所有功能均无效.我已经删除了所有内容,所以我只有一个页面,上面有几个发布按钮,但仍然不会调用Post方法.有谁知道发生了什么事?

When the page loads it will call the Get function and the page will display, but none of the functionality on the view works. I have deleted everything so I just have 1 page with a couple of post buttons on it, and still it will not call the Post method. Does anyone have any idea what is going on?

这是我的观点:

@page
@model FloorCore.Areas.Jobs.Pages.JobIndexModel
@{
}

<form method="post">
    <button class="btn btn-default">Click to post</button>
    <button type="submit" class="btn btn-primary">Click to post</button>
</form>

这是控制器:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace FloorCore.Areas.Jobs.Pages
{
    public class JobIndexModel : PageModel
    {
        public void OnGet()
        {
            int for_breakpoint = 0;
        }

        public void OnPost()
        {
            int for_breakpoint  = 0;
        }
    }
}

单击任一按钮只会返回:此页面无法正常工作.如果问题仍然存在,请与网站所有者联系.HTTP错误400

Clicking on either button just returns: This page isn’t working. If the problem continues, contact the site owner. HTTP ERROR 400

未调用控制器上的OnPost方法.

The OnPost method on the controller is not called.

推荐答案

我回来回答自己的问题是因为我找出了问题所在,这也许会对其他人有所帮助.我在此特定区域中缺少_ViewImports文件.

I came back to answer my own question because I figured out what the problem was and perhaps this will help someone else. I was missing the _ViewImports file in this particular Area.

_ViewImports包含以下行:

The _ViewImports contained the following line:

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

我需要使用它来使我的助手方法起作用.

which I needed in order for my helper methods to work.

这篇关于为什么我的Razor Page方法没有被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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