小编Rya*_*ill的帖子

ErrorMessageResourceName和ErrorMessage不能同时设置,但我只设置一个

这是我使用MVC2时遇到的错误:

Either ErrorMessageString or ErrorMessageResourceName must be set, but not both.
Run Code Online (Sandbox Code Playgroud)

它来自[Required] Validation DataAnnotation.

堆栈跟踪:

InvalidOperationException: Either ErrorMessageString or ErrorMessageResourceName must be set, but not both.]
   System.ComponentModel.DataAnnotations.ValidationAttribute.SetupResourceAccessor() +89338
   System.ComponentModel.DataAnnotations.ValidationAttribute.FormatErrorMessage(String name) +38
   System.Web.Mvc.<Validate>d__1.MoveNext() +215
   System.Web.Mvc.<Validate>d__5.MoveNext() +735
   System.Web.Mvc.DefaultModelBinder.OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext) +424
   System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +732
   System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +475
   System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +152
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +709
   System.Web.Mvc.Controller.ExecuteCore() +162
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +58
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371
Run Code Online (Sandbox Code Playgroud)

我把我的视图模型煮到了这个(它会在任何时候出现[Required]属性,在没有的情况下工作正常):

[Required(ErrorMessage = "")]
[DataType(DataType.Text)]
[DisplayName("Property Name")] …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc asp.net-mvc-2

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

Html助手不再能够推断出类型参数

完整错误文字:

The type arguments for method 'System.Web.Mvc.Html.DisplayExtensions.DisplayFor<TModel,TValue>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,TValue>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Run Code Online (Sandbox Code Playgroud)

它刚刚开始发生,但我不相信我做了任何会影响此功能的更改.抛出VS intellisense错误,但页面功能正常.

不是"For"帮助程序的Html帮助程序工作得很好,它只是包含这些表达式的帮助程序.

违规标记(100个例子):

 <%: Html.DisplayFor(model => model.PortfolioName) %>    
Run Code Online (Sandbox Code Playgroud)

页面指​​令:

<%@ Page Language="C#" Inherits="ViewPage<My.Namespace.PortfolioViewModel>" %>
Run Code Online (Sandbox Code Playgroud)

查看型号:

namespace My.Namespace
{
    public class PortfolioViewModel
    {
        [Required(ErrorMessage = " ")]
        [DataType(DataType.Text)]
        [DisplayName("Portfolio Name:* ")]
        public string PortfolioName { get; set; }
     }
}
Run Code Online (Sandbox Code Playgroud)

.net model-view-controller asp.net-mvc asp.net-mvc-2

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

代码未通过首次验证

我有一个函数,我首先检查作为参数传递的字符串是否只有字母.但它总是以虚假的方式回归.下面是我的jsfiddle

function takeString (str) {
    var regex = "/^[A-Za-z]+$/";

    if (str.match(regex)) {
        if (str.charCodeAt(0) === str.toUpperCase().charCodeAt(0)) {
            alert('true');
            return true;
        } 
        else {
            alert('false');
            return false;
        }
    } 
    else {
        alert('Only letters please.');
    }
}

takeString('string');
Run Code Online (Sandbox Code Playgroud)

以上代码始终提醒Only letters please.

javascript regex jquery

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

使用 nextjs App Router 进行服务器端渲染和动态客户端

我在 NextJs 中经常使用的一种模式是渲染服务器端的所有内容(包括数据获取),然后过渡到动态客户端渲染。人为的例子:

export async function getServerSideProps() {
  const res = await fetch(`api/myData`)
  const data = await res.json()

  return {
    props: { initialData: [data] }
  }
}

export default function About({ initialData }) {
  const [data, setData] = useState(initialData)

  const addItem = () => {
    const item = "foo"
    const res = await fetch('/api/addData')
    setData([...data, JSON.parse(res.body).item])
  }

  return (
    <div>
      {data.map(item => (<div>{item}</div>))}
      
      <button onClick={addItem}>Add Item</button>
    </div>
  )
}
Run Code Online (Sandbox Code Playgroud)

我不知道如何通过构建 NextJs 的新 App Router 风格获得相同类型的功能。谁能告诉我我缺少什么?

reactjs next.js

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

node-inspector窗口为空白

通过npm install -g nodeinspector安装了node-inspector.

我可以到达仪表板,但它在搜索栏外面只是空白.

我已经尝试在各种订单中启动app/inspector/browser并重新安装了node-inspector几次.有人建议我手动安装连接和异步模块,但没有用.

有帮助吗?

在此输入图像描述

node.js node-inspector

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

git commit --amend 不提交更改

任何时候我在本地进行更改并执行任一操作git commit --amend,然后:x保存并关闭 vim 或者甚至只是git commit --amend --no-edit什么也没有发生。没有提交或上演任何本地更改。我完全困惑这怎么可能。其他rebaseing 活动与编辑器正常工作。

\n\n

这是完整的工作重现:

\n\n
amendwtf|master \xe2\x87\x92 ls\nfile\namendwtf|master \xe2\x87\x92 git status\nOn branch master\nnothing to commit, working tree clean\namendwtf|master \xe2\x87\x92 echo \'a change appears\' > file\namendwtf|master\xe2\x9a\xa1 \xe2\x87\x92 git status\nOn branch master\nChanges not staged for commit:\n  (use "git add <file>..." to update what will be committed)\n  (use "git checkout -- <file>..." to discard changes in working directory)\n\n    modified:   file\n\nno changes added to commit (use "git add" and/or …
Run Code Online (Sandbox Code Playgroud)

git

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