小编glo*_*rob的帖子

控制器未收到英国格式的MVC3日期

鉴于这个VM

public class ApplicationDTO : BaseDTO
{
    public DateTime Date { get; set; }
    public int JobId {get;set;}
    public int Status {get;set;}
    [Required]
    public string Message { get; set; }
    public string ExpertCode { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

因此,我有一个隐藏的领域

@Html.Hidden("Date", DateTime.Now)
Run Code Online (Sandbox Code Playgroud)

哪个小提琴手告诉我的是按照我的预期发送到服务器(英国格式,我在英国!)

在此输入图像描述

但在控制器上,日期显示为默认最小值.日期

在此输入图像描述

它只是英国格式吗?如果是这样,我最好的方式是什么呢?虽然目前我将其设置为当前日期,但可能会将其设置为任何给定日期,即

@Html.HiddenFor(x => x.Date)
Run Code Online (Sandbox Code Playgroud)

我正在使用AJAX提交表单,如果这有所不同.

c# ajax asp.net-mvc datetime

4
推荐指数
1
解决办法
3159
查看次数

如何在MVC中为所有视图提供Html助手?

也许这对程序员来说是一个问题 - 我相信如果有的话,有人会建议我.

当使用MVC时,我也可以访问Html Helper变量并使用任何扩展方法,无论是.Net的还是我自己指定的.

@Html.Raw("<h1>This is my HTML</h1>")
Run Code Online (Sandbox Code Playgroud)

这是如何实现的?假设我想为了另一个原因添加一个单独的对象,并将其提供给我的MVC应用程序中的所有视图?

我知道我无法将其添加到控制器,因为一个视图可能被多个控制器访问.

所以我最好的猜测是需要继承IView?

编辑:抱歉 - 我没有解释自己.至少我认为......

我希望对象可用,但也要实例化.例如,假设我有一个名为的对象glosrob,有一个方法,SayHello()并希望能够如此使用它:

@glosrob.SayHello()
Run Code Online (Sandbox Code Playgroud)

基本上我想避免在每个视图上添加代码来构造对象,例如避免这种情况

@{
    var glosrob = new Glosrob();
}
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net-mvc

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

ASP.Net MVC SelectList不是'选择'正确的项目

我被要求查看一些ASP.Net MVC代码中的错误,并且(对我来说)SelectList有一个非常奇怪的问题.

来自控制器的代码生成项(返回SelectList的方法,总共有5个).然后将每个SelectList保存到ViewData集合中.

List<SelectListItem> items = new List<SelectListItem>();
string yesText = "Yes";
string noText = "No";
if (ci.LCID.Equals((int)LanguageCodes.FRANCE))
{
    yesText = "Oui";
    noText = "Non";
}

SelectListItem yesItem = new SelectListItem();
yesItem.Text = yesText;
yesItem.Value = ((int)MarketingBy.Yes).ToString();
yesItem.Selected = selectedValue != null && selectedValue.Equals(int.Parse(yesItem.Value));

SelectListItem noItem = new SelectListItem();
noItem.Text = noText;
noItem.Value = ((int)MarketingBy.No).ToString();
noItem.Selected = selectedValue != null && selectedValue.Equals(int.Parse(noItem.Value));

items.Add(yesItem);
items.Add(noItem);

return new SelectList(items, "Value", "Text", yesItem.Selected ? yesItem.Value : noItem.Value);
Run Code Online (Sandbox Code Playgroud)

在创建点快速"快速观察"表明一切正常: 选择列表生成http://i52.tinypic.com/x3hd3r.png

在渲染视图时,值仍然可以正常显示.但是,加载视图时,始终会选择列表中的第一个项目.生成的HTML是:

<tr> …
Run Code Online (Sandbox Code Playgroud)

html selectlist asp.net-mvc-2

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

NCrunch显示未经测试的循环括号

考虑下图中显示的代码块:

在此输入图像描述

有一个讨厌的黑色/'这行代码没有被任何测试点覆盖.

任何能够阐明任何测试都没有涵盖这一点的任何人,考虑到它是指一个foreach循环的闭合支撑?

如果环的其余部分被覆盖(全部为绿色),那么退出时肯定会击中端部支撑foreach

ncrunch

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

具有不同参数类型的MVC3路由

我很难在MVC3中解决路由问题.

以前我一般只是避开整个区域,并坚持丑陋的老式?id=1&foo=bar网址.不太好.

我这样定义了4条路线

routes.MapRoute("Blog", "{controller}/{action}/{PageNumber}/{PostsPerPage}", new { controller = "blog", action = "list", PageNumber = UrlParameter.Optional, PostsPerPage = UrlParameter.Optional });
routes.MapRoute("Code", "{controller}/{action}/{title}", new { });
routes.MapRoute("Id", "{controller}/{action}/{id}", new { });
routes.MapRoute("Default", "{controller}/{action}", new { controller = "home", action = "index" });
Run Code Online (Sandbox Code Playgroud)

我试图从最具体到最少的顺序排序.

第一个"博客"路线工作正常,我可以使用类似的URL /blog/list/2/5,它正确映射到我的控制器.

底部的默认路线也正如我所料.

但是如果我有这样的动作方法:

public ActionResult BarX(int id)
{
    //some stuff
}

public ActionResult BarY(string title)
{
    //some stuff
}
Run Code Online (Sandbox Code Playgroud)

我希望它使用第三条路线并生成一个类似的URL /foo/barX/3.

但是,如果我使用

@Html.ActionLink("TEST1", "barX", "foo", new { id = 3 }, null)
Run Code Online (Sandbox Code Playgroud)

生成的URL是 …

asp.net asp.net-mvc routes asp.net-mvc-routing asp.net-mvc-3

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

无法将类型“Microsoft.AspNetCore.Mvc.NotFoundResult”隐式转换为“System.Threading.Tasks.Task”

考虑这样的控制器操作:

[HttpGet]
[Route("blog/{slug}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<Blog> Get(string slug)
{
    return await Task.Run(() =>
    {
        var model = Data.GetBlog(slug);
        if (model == null)
        {
            return NotFound();
        }
        return Ok(model);
    });
}
Run Code Online (Sandbox Code Playgroud)

我收到每个返回的错误:

Cannot implicitly convert type 'Microsoft.AspNetCore.Mvc.NotFoundResult' to 'System.Threading.Tasks.Task'
Cannot implicitly convert type 'Microsoft.AspNetCore.Mvc.OkObjectResult' to 'System.Threading.Tasks.Task'
Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
Run Code Online (Sandbox Code Playgroud)

如果我注释掉其中一种响应类型(所以只有NotFound()或只有Ok()),它编译得很好。

我认为两者都继承自同一个基类,因此两者都可以在同一个操作中使用。

我哪里错了? …

c# asp.net-web-api asp.net-core

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

使用 Babel 运行 Webpack5 时出错:找不到模块“fs/promises”

尝试让 Babel 和 Webpack 5 很好地协同工作,但我收到以下错误:

Module build failed (from ./node_modules/babel-loader/lib/index.js):
Error: Cannot find module 'fs/promises'
Run Code Online (Sandbox Code Playgroud)

我看到的大多数链接都引用旧版本的 Node(最常提到 v12),但运行时node -v我可以看到安装了以下版本:

v18.12.1
Run Code Online (Sandbox Code Playgroud)

Package.json 看起来像这样

{
  "name": "foobar",
  "version": "1.0.0",
  "description": "Trying out webpack 5 and babel.",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "babel": {
    "presets": [
      "@babel/preset-env"
    ]
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.20.2",
    "@babel/preset-env": "^7.20.2",
    "babel-loader": "^9.1.0",
    "terser-webpack-plugin": "5.3.0",
    "typescript": "^4.9.3",
    "webpack": "^5.75.0",
    "webpack-cli": "^4.4.0",
    "webpack-dev-server": "^3.1.1" …
Run Code Online (Sandbox Code Playgroud)

webpack babel-loader webpack-5

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

尝试通过插件注册加载插件时出错.工具

目前为止的步骤:

  • 从MS下载的注册工具
  • 内置
  • 部署到CRM App Server(Win2k8机器)
  • 已加载并使用Deployment Admin帐户登录
  • 添加新装配
  • 浏览到插件库
  • 按打开
  • 错误!

    未处理的异常:System.IO.FileLoadException:无法加载文件或程序集'file:/// C:\ crmtools\PluginRegTool\PluginRegTool_1708_New_From_SDK\PluginRegistration.exe'或其依赖项之一.不支持操作.(HRESULT异常:0x80131515)

内部例外说:

System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. 
This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. 
If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See …
Run Code Online (Sandbox Code Playgroud)

exception dynamics-crm dynamics-crm-2011

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

CRM 2011 Online - 插件中的无限循环错误 - 无法找到它

我正在使用以下插件,该插件在更新机会时执行:

public class PreOpportunityWin : Plugin
{
    public PreOpportunityWin() : base(typeof(PreOpportunityWin))
    {
        base.RegisteredEvents.Add(
        new Tuple<int, string, string, Action<LocalPluginContext>>(20, "Update", "opportunity", new Action<LocalPluginContext>(ExecuteAutonumber)));
    }

    protected void ExecuteAutonumber(LocalPluginContext localContext)
    {
        Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)localContext.PluginExecutionContext;
        if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
        {
            //Organization Service
            IOrganizationService service = localContext.OrganizationService;
            //Tracing Service
            ITracingService trace = (ITracingService)localContext.TracingService;

            Entity Target = (Entity)context.InputParameters["Target"];
            var entity = service.Retrieve(
            Target.LogicalName, Target.Id, new ColumnSet(true));
            var entityStatusCode = (OptionSetValue)entity.Attributes["statuscode"];
            if (entityStatusCode.Value == 3)
            {
                //Code to execute if opportunity won
                trace.Trace("In the …
Run Code Online (Sandbox Code Playgroud)

c# plugins dynamics-crm-2011

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

通过插件更新持续时间字段

有没有人必须Duraton从插件中更新字段?

在UI上,它非常智能,您可以输入

  • 5 minutes
  • 7 //defaults to minutes
  • 3 hours

它会锻炼你需要的东西.

假设调用该字段new_foo,我应该分配什么值?诠释?

var e = new Entity("new_bar");
e.Attributes("new_foo", 5);//5 minutes?
Run Code Online (Sandbox Code Playgroud)

双?

var e = new Entity("new_bar");
e.Attributes("new_foo", 5.00);//5 minutes?
Run Code Online (Sandbox Code Playgroud)

其他想法?

dynamics-crm-2011

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

'Gulpfile.js - 加载失败查看输出'但输出没有显示任何错误信息

我试图用一口一些JS / CSS从复制node_moduleswwwroot在一个ASP.Net核心应用。

我有我认为相当简单的 gulpfile.js

var gulp = require('gulp');
gulp.task('copy-files', function () {
    var assets = {
        js: [
            './node_modules/bootstrap/dist/js/bootstrap.js'
        ],
        css: [
            './node_modules/bootstrap/dist/css/bootstrap.css'
        ]
    };
    _(assets).forEach(function (assets, type) {
        gulp.src(assets).pipe(gulp.dest('./wwwroot/' + type));
    });
});
Run Code Online (Sandbox Code Playgroud)

但是,当我查看 VS Task Runner 时,它只显示一个错误: 在此处输入图片说明

但是输出窗口是空的: 在此处输入图片说明

如何获得有关错误的更多信息?

visual-studio gulp

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