小编Joh*_*n D的帖子

.NET MVC4 ActionNameSelectorAttribute视图中的多个按钮不起作用

我已经阅读了许多关于允许不同的视图按钮使用不同的控制器动作的文章。但是,我无法使它正常工作。

我使用从http://blog.ashmind.com/2010/03/15/multiple-submit-buttons-with-asp-net-mvc-final-solution/获得的代码段。

public class HttpParamActionAttribute : ActionNameSelectorAttribute 
{
    public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo) 
    {
        if (actionName.Equals(methodInfo.Name, StringComparison.InvariantCultureIgnoreCase))
            return true;

        if (!actionName.Equals("Action", StringComparison.InvariantCultureIgnoreCase))
            return false;

        var request = controllerContext.RequestContext.HttpContext.Request;
        return request[methodInfo.Name] != null;
    }
}
Run Code Online (Sandbox Code Playgroud)

当我通过这个代码一步,我看到一个比较actionNamemethodInfo.Name。当整个目的是要命名与控制器动作不同的方法时,这些EVER怎么相等。

对于行为/功能,true或false的返回值实际上意味着什么?

我是否应该将“ fciContactUs”操作替换为“ Action”?

控制器=“ HomeController”

  [HttpParamAction]
  [ActionName("Action")]
  [AcceptVerbs(HttpVerbs.Post)]
  [ValidateInput(false)]
  public ActionResult DoClearForm(fciContactUs p_oRecord)
  {
     return RedirectToAction("fciContactUs");
  }

  [HttpParamAction]
  [ActionName("Action")]
  [AcceptVerbs(HttpVerbs.Post)]
  public ActionResult TrySubmit(fciContactUs p_oRecord)
  {
     // This must be the Submit command.
     if (ModelState.IsValid) …
Run Code Online (Sandbox Code Playgroud)

controller view button razor asp.net-mvc-4

3
推荐指数
1
解决办法
3776
查看次数

ASP.NET 和 SQL Server:#temp-table 可以由 ASP.NET Webforms 应用程序使用吗?

在我们使用 SQL Server 的 ASP.NET 4.6 Webforms 应用程序中,我们希望页面使用#temptable,但我们无法让它工作。Page1在 SQL Server 中创建#temptable,然后启动Page2将其放入要#temptable在网格内编辑的 GridView 中。

当加载并且对浏览器可见时, 的范围#temptable似乎不会超出Page1服务器范围。Page2

我们正在考虑使用数据库本身的表,而不是#temptable. 此外,其他用户可能能够编辑相同的表,但使用不同的“数据”。我们认为这#temptable将属于特定用户(来自浏览器)。

任何指导将不胜感激。谢谢...约翰。

答案:根据@Faruq的解释,我们将为每个用户使用一个普通的数据库表。

asp.net webforms sql-server-2012

2
推荐指数
1
解决办法
1919
查看次数

Blazor 错误:“没有该类型的注册服务”——其他 StackOverflow 问题无法解决

在我的 .Net CORE 5(导入的支持文件 v5.0.12)Blazor PWA VS-2019 解决方案中,我“拥有”一个工作的“客户”-(数据/应用程序)服务和 Blazor 页面来列出和 CRUD 客户记录(工作原理为预期的)。我为服务器项目和客户端项目创建了类似的“车辆”文件(当然更改了模型字段引用)。

目前还没有编译错误,当我尝试显示“VehicleList”页面时,此错误出现在输出窗口中:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] 未处理的异常渲染组件:无法为类型 'MyCore5AppPWA.Client.Pages.VehicleList'上的属性'_vehicleService'提供值。没有类型为'MyCore5AppPWA.Client.Services.IVehicleService'的已注册服务。System.InvalidOperationException:无法为类型'MyCore5AppPWA.Client.Pages.VehicleList'上的属性'_vehicleService'提供值 。 没有类型为'MyCore5AppPWA.Client.Services.IVehicleService'的已注册服务。在 Microsoft.AspNetCore.Components.ComponentFactory.<> c__DisplayClass6_0 .g__Initialize|2(IServiceProvider serviceProvider,IComponent 组件)

请注意上面的“...c__DisplayClass6_0...”符号,这对我来说很好奇(不知道其意义)。我已经阅读了许多与本文主题相关的类似问题/答案,但这些问题/答案并未纠正错误。

以下是 Startup.cs 文件中的片段:

  public void ConfigureServices(IServiceCollection services) {

     _ = services.AddDbContext<AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DbConnection")));

     services.AddScoped<ICustomerRepository, CustomerRepository>();
     services.AddScoped<IVehicleRepository, VehicleRepository>();

     services.AddControllersWithViews();
     services.AddRazorPages();

     services.AddScoped<WeatherForecastService>();

  }
Run Code Online (Sandbox Code Playgroud)

以下是“VehicleList.razor”代码文件中的片段。

//html... declarations.
@layout MainLayout
@page "/vehiclelist"
@using MyCore5AppPWA.Client.Services;
@using MyCore5AppPWA.Shared
//...html omitted...//

@code {

   [Inject] 
   private IVehicleService _vehicleService { get; set; …
Run Code Online (Sandbox Code Playgroud)

c# progressive-web-apps asp.net-core blazor-webassembly

2
推荐指数
1
解决办法
1万
查看次数

有没有更简单的方法来编写以下 C# 语句

是否有更简单或替代的方法来编写以下 C# 句子?

if (iValue >= 4 && iValue <= 10) {... other code ...}
Run Code Online (Sandbox Code Playgroud)

我需要重复iValue两次吗?

我见过类似的结构,_ = ...some code... 但我不熟悉那个前导下划线?

c#

0
推荐指数
1
解决办法
79
查看次数

在将结果返回到控制器之前是否可以过滤存储库模式获取的数据?

该项目是 C# VS-2022 Blazor WASM,具有用于数据库 API 的 REST-API 存储库模式。

每当我在存储库函数中使用Where()条件时,我都会收到编译错误。

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

例如在存储库函数中:

returnRecs = (await appDbContext.MOTrip).Where(r => (r.UID_CUSTOMER == uidModel));
Run Code Online (Sandbox Code Playgroud)

我尝试在存储库中进行过滤的原因是因为数据库表“MoTrip”包含数十万条记录。我认为(await appDbContext.MOTrip)在控制器中获取所有记录并遵循各种过滤条件将是浪费。

在此问题中提出的情况下,按 CUSTOMER 进行过滤将是存储库功能获取的记录数的 1/100。

欢迎您的回答和评论。谢谢约翰。

c# repository-pattern blazor-webassembly

0
推荐指数
1
解决办法
331
查看次数