You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复Error CS1738:命名参数必须位于所有固定参数之后

解决Error CS1738:命名参数必须出现在所有固定参数之后

方法1:调整参数传递写法

去掉命名参数标识

直接移除htmlAttributes:前缀,让参数按位置传递即可:

<div class="form-group col-md-4">
@Html.LabelFor(model => model.SubjectId)
@Html.DropDownListFor(model => model.SubjectId, Model.ListOfSubject, new { @class = "form-control", @id = "txtTotalMarks" })
</div>

统一使用命名参数

给所有参数都加上命名标识,这样参数顺序不受限制:

<div class="form-group col-md-4">
@Html.LabelFor(expression: model => model.SubjectId)
@Html.DropDownListFor(expression: model => model.SubjectId, selectList: Model.ListOfSubject, htmlAttributes: new { @class = "form-control", @id = "txtTotalMarks" })
</div>

方法2:升级C#语言版本到7.2+

如果想保留原代码的写法,需要修改项目的语言版本设置:

  • 右键项目 → 选择「属性」
  • 切换到「生成」标签页,点击「高级」按钮
  • 在「语言版本」下拉框中选择C#7.2或更高版本(比如C#8.0、C#9.0)

这样就能支持非末尾的命名参数写法了。

内容的提问来源于stack exchange,提问作者nathan prescott

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 07:05:16