我在 RazerPages 应用程序中收到 CS1061 错误,告诉我定义不存在,但确实存在,有人可以向我指出这个问题吗?

问题描述 投票:0回答:1

我正在开发一个 CRUD ASP.NET Razor Pages 应用程序,该应用程序允许用户搜索大陆、国家,并添加和远程有关它们的数据。我收到以下有关索引页索引模型的错误:

错误 CS1061“IndexModel”不包含“SearchString”的定义,并且找不到接受“IndexModel”类型的第一个参数的可访问扩展方法“SearchString”(您是否缺少 using 指令或程序集引用?)

public List<Country> Countries { get; set; }
        

        public async Task OnGetAsync()
        {
            var countries = from c in _context.Countries
                            select c;

            if (!string.IsNullOrEmpty(SearchString))
            {
                countries = countries.Where(c => c.Name.Contains(SearchString));
            }

            Countries = await countries.ToListAsync();
        }

        public async Task<IActionResult> OnPostAsync(string id)
        {
            if (id == null)
            {
                return NotFound();
            }

            Country Country = await _context.Countries.FindAsync(id);

            if (Country != null)
            {
                _context.Countries.Remove(Country);
            }

            await _context.SaveChangesAsync();

            return RedirectToPage("./Index");
        }

        [BindProperty(SupportsGet = true)]
        public string SearchString { get; set; }
    } ```

Can someone point out to me why I am getting the error? 
c# asp.net-core razor-pages
1个回答
0
投票

发现问题,我应该使用以下 using 指令:

@using RazorCountry.Pages.Countries
© www.soinside.com 2019 - 2024. All rights reserved.