在使用Mvc ”FormCollection “ +“ValidationSummary”和“ValidationMessage” 验证数据时的小问题

VSLAM框架对比 格VSLAM特点介绍: (一)ORB-SLAM2 (二)ORB-SLAM3 (三)LSD-SLAM (四) 阅读详情

在使用Mvc ”FormCollection “ +“ValidationSummary”和“ValidationMessage” 验证数据时的小问题

2010-10-25

 

初始的测试代码:

 

在预览时是正常的,但是提交时回报

如下的类似的错误

未将对象引用设置到对象的实例。

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:

行 28:                     </td>
行 29:                     <td>
行 30:                         <%=Html.TextBox("txt_userName")%>
行 31:                         <%=Html.ValidationMessage("txt_userName", "用户名不能为空!")%>
行 32:                     </td>

 

 

这是因为

       当传递FormCollection参数时,不使用UpdateModel方法,但在验证失败后调用ModelState.AddModelErro方法时,System.Web.Mvc.ModelState被实例化,并通过某个键值(比如“Title”)加入到了ModelState集合中。但是,该System.Web.Mvc.ModelState实例的Value属性是NULL的。

      当在View中使用HtmlHelper.TextBox("Title")进行渲染的时候,HtmlHelper试图通过键值(“Title”)重新将输入值与控件绑定(例如:TextBox)时,由于ModelState集合的优先级最高,因此HtmlHelper试图通过这个键值(“Title”)从ModelState集合中获取数据(通过调用GetModelStateValue()方法)。由于AddModelErro方法的“功劳”,HtmlHelper获取到了这个键值(“Title”)对应的System.Web.Mvc.ModelState类的实例,但该实例的Value属性是Null。因此,出现了开篇的问题:“未将对象应用设置到对象值的实例”。

 

问题解决后的代码

 

其中问题解决的关键代码:

 

 

.NET MAUI 第13讲 深入探索 .NET MAUI Essentials:让应用感知设备与环境,打造智能体验 摘要:本文介绍了.NET MAUI Essentials库如何赋能移动应用感知设备环境的能力。文章详细讲解了设备信息获取(DeviceInfo)、网络状态监测(Connectivity)、地理位置服务(Geolocation)、地图集成(Map)以及传感器(Accelerometer等)等核心功能的使用方法,并提供了完整的代码示例。通过一个综合练习,展示了如何构建设备信息仪表板,实时显示设备参数和网络状态,并实现位置获取与地图导航功能。这些跨平台API能显著提升应用智能化和用户体验,同时保持代码简洁高效。 阅读详情

相关推荐

faster lio 回环 加入GTSAM优化的记录

对Faster lio 加入回环、gtsam优化,在室外建图遇到的问题和过程

Nico_jion的博客 2599

Spring常见问题解决 - 对象参数校验失效

进行参数校验的时候,请在Controller参数入口处,增加@Validted注解。倘若有级联属性,类里面嵌套类。需要在对应的属性上增加@Valid注解来表示支持级联校验。

Zong_0915的博客 4188

Windows 10 本地开发环境:用 ShardingSphere-Proxy 5.4.1 快速搭建 MySQL 分库分表测试环境

本文详细介绍了在Windows 10系统中使用ShardingSphere-Proxy 5.4.1快速搭建MySQL分库分表测试环境的完整教程。从环境准备、MySQL配置到ShardingSphere-Proxy的核心设置,逐步指导开发者完成本地开发环境的搭建,并提供了分片策略详解和常见问题排查方法,帮助开发者高效验证分库分表功能。

weixin_28366053的博客 214

SpringBoot的数据校验(@Validated注解)、关于validation无法导入的问题解决、自定义校验注解

在springboot中,@Validated可对后台接收model进行数据校验,不符合则抛出异常。 使用样例: 1.在实体类中定义注解 @Data @EqualsAndHashCode(callSuper = false) @TableName("sys_role") @ApiModel(value="Role对象", description="") public class Role implements Serializable { private static final long ser

qq_51269815的博客 2462

分析方法—temporal receptive field(TRF)

总结来说,时间感受野其实就是一个 filter!课程中的描述—.(使用时间感受野与刺激进行卷积来描述)时间感受野一般是听觉计算中使用的,在视觉中,有另一种分析叫做空间感受野(spatial receptive fields)。回归权重(Regression weights)是指在回归分析中用于估计自变量与因变量之间关系的权重或系数。回归分析是一种统计方法,用于建立自变量与因变量之间的关联模型,并通过拟合数据来估计模型中的参数。在简单线性回归中,只有一个自变量与一个因变量之间的关系被建模。

m0_51474171的博客 1602

STM32学习笔记 二、基于STM32F103C8T6和STM32CubeMX实现UART串口通信数据收发

系列文章目录 一、基于STM32F103C8T6最小系统板和STM32CubeMX实现LED灯循环闪烁 文章目录系列文章目录前言一、配置CubeMX二、逻辑代码部分 前言 这次我用的板子是一个用STM32F103C8T6作为主控芯片的一个数据采集卡,两个LED灯连接的引脚是PB3与PB4,TX与RX引脚分别是PA9和PA10。 一、配置CubeMX 1、新建工程; 2、配置时钟源,在RCC里面的HSE配置的是晶振时钟; 3、配置程序烧录引脚SYS为SWD模式; 4、配置GPIO口,配置一个LE

遗忘丶的博客 1万+

在Winform中上传文件的工具类-ResourceMgr

ResourceMgr是一个可扩展可定制的上传工具类,它提供上传进度和状态指示。配合可视化的组件,有类似于快车或迅雷下载软件的效果。 它的基类的完整实现如下:由于我是在应用程序整体框架中抠出来的代码,所以有些可能是不属于.net自带的类库中的方法。 using System; using System.IO; using System.ServiceModel; using Aosu...

weixin_33805743的博客 217

【75】OpenCV C++实战篇——OpenCV 图像拼接、全景拼接(教程合集)

本文整理了OpenCV实现图像拼接的技术教程合集,涵盖C++和Python两种语言实现方案。图像拼接技术旨在将多张重叠图像融合为无缝全景图,既扩大视角又保持高分辨率。内容包含水平矫正等关键步骤(附对比效果图),提供多个实战案例的完整代码和详细讲解,涉及单应性矩阵、图像变换等核心技术。不同案例展示了从两张到多张图像的拼接效果,适合不同层次的学习者参考实践。

程序员,他们想的是什么?他们想的永远都是技术,他们崇尚的也永远都是技术。 528

GLM-5.3-Flash部署实战:从API接入到多卡生产级推理服务

大模型推理部署是AI应用从原型走向落地的关键环节,涉及模型选型、显存规划、推理引擎调优与高并发服务治理等一系列工程决策。在开源与商用大模型能力日趋接近的背景下,如何用可控成本获取稳定高效的推理服务,成为算法工程师与运维团队共同关注的核心议题。推理引擎vLLM通过连续批处理、前缀缓存、PagedAttention等机制有效优化显存利用率与吞吐性能,而OpenAI兼容接口的普及则让模型切换与多模型路由变得标准化。无论是面向私有化部署的单机异构方案,还是支撑大规模在线业务的多卡并行架构,都需要在模型效果、硬件投入

weixin_34133829的博客 505

全功能tgbot/Telegram机器人多功能有后台版源码

trx兑换 闪兑 关键字监控 群管 usdt监控 余额查询 推广分享 等几乎常见的tg机器人功能都有。全功能tgbot/telegram机器人多功能有后台版源码-打包好的可以直接上手。

百创科技 2699

压缩包密码破解工具ZIP Cracker2.0.1.2 正式版

一款多功能文件密码破解工具,支持ZIP、RAR、Office等主流加密格式,提供CPU/GPU双模式破解。该软件采用黑客风格界面,具备环境自检修复功能,支持实时监控硬件使用率。内置hashcat等专业破解工具,通过拖拽文件即可快速破解,GPU模式速度可达CPU的10-100倍。最新版本优化了中文路径支持,并提升了启动速度。

bfq05234214的博客 481

ASP.NET MVC 入门8、ModelState与数据验证

ViewData有一个ModelState的属性,这是一个类型为ModelStateDictionary的ModelState类型的字典集合。在进行数据验证的时候这个属性是比较有用的。在使用Html.ValidationMessage()的时候,就是从ViewData.ModelState中检测是否有指定的KEY,如果存在,就提示错误信息。例如在前一篇文章ASP.NET MVC 入门7、Hellp

prefercent的专栏 498

基于Simulink的电动车PMSM能量泄放与回收系统仿真设计

摘要 本文设计了一个基于Simulink的电动车PMSM能量泄放与回收系统仿真模型。系统采用分层建模方案,包含永磁同步电机(PMSM)矢量控制、电池管理和泄放功率计算等核心模块。通过详细的参数计算和MATLAB脚本实现,模拟了电动车在制动时的能量回收过程。重点研究了泄放电阻的控制策略,提出基于母线电压和电池SOC的多目标优化算法,确保系统在保护硬件安全的同时最大化能量回收效率。仿真模型包含完整的数学推导和模块搭建指南,为电动车能量管理系统设计提供了有效的仿真验证平台。

huanghm88的专栏 193

关于ValidationSummary,也就是mvc的客户端错误验证的理解

思路 在对象初始化的时候进行的错误验证,mvc是viewdate传递的,而接收的时候如果是以表单提交,表单所有数值均是对象的属性的时候,在属性初始化的时候会进行判断的,具体步骤如下 第一步,在对象中增加 [MetadataType(typeof(SYS_autoan))] public partial class autoan //这个是与对象相同的名字,对象名字要是au

飞鸟的博客 973

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

ASP.NET MVC 3 Validation - 谨慎ValidationMessage的误触发

使用Html.ValidationMessageFor即可扩展显示Error Message。 默认的表达格式如下: validationMessage or defaultErrorMessage 需要注意的是,错误的验证是再ModelState去

实践与分享 1万+

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

FormCollection获取请求数据

public ActionResult Add(FormCollection fm) //通过FormCollection 对象获取表单数据 { string message = ""; string desc = ""; bool flag = false; var WritDocName = fm["WritDocName"]; var Time = fm["Time"]; ...

weixin_30410999的博客 593

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Formcollection取值

1.前台需要form表单 eg: 姓名: 年龄: 19 20 21

qq_31752831的博客 5939

车牌识别,部分错误C++ Call Stacks (More useful to developers):Error Message Summary:

《百度顶会论文复现营》其中作业《车牌识别》部分,运行代码出现错误。 解决方法和原因,在错误信息下面 定义DNN网络如下错误信息如下: train_pass:0,batch_id:50,train_loss[0.28051484],train_acc:[1.] train_pass:0,batch_id:100,train_loss[1.2990379],train_acc:[1.] train_pass:0,batch_id:150,train_loss[0.5766834],train_acc:[1.]

weixin_43958308的博客 1479

ValidationSummary控件无法弹出错误提示框

使用控件RequiredFieldValidator加上ValidationSummary,验证必填项是否为空,若为空则在消息框中显示错误,实际测试中发现并不弹出消息框。甚至页面会显示“[color=yellow]WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add

localhost 2367

安装paddlepaddle报错解决

安装paddle python3 -m pip install paddlepaddle-gpu 出现报错: g>(paddle::AnalysisConfig const&) ---------------------- Error Message Summary: ---------------------- ExternalError: Cuda error(35), CUDA driver version is insufficient for CUDA runtime

猫猫与橙子的博客 7733

百度Paddlepaddle-GPU运行时出现Error: Cannot load cudnn shared library. Cannot invoke method cudnnGetVersion

这里写目录标题一级目录二级目录三级目录 一级目录 二级目录 三级目录

风月同天的博客 2万+
上一篇: 关于Html.DropDownList
下一篇: 标识列顺序排列问题
Pro_ah
博客等级 码龄17年 93粉丝 6原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值