我正在尝试使用Entity Framework构建我的第一个ASP.net MVC应用程序。它没事,但我有问题。我使用自定义用户系统,因此我有一个用于创建和编辑用户的页面。在创建视图中,显然我有用户名和密码字段,但我不想在编辑视图中使用它们。问题是它们具有[Required]
属性,因此如果我从编辑页面中删除它们,则值将变为null并且它会给出验证错误。我可能在这里很容易丢失一些东西,不确定。
有什么想法吗?感谢。
答案 0 :(得分:0)
如果您希望在提交时将值发布到MVC,而不想显示,请在剃刀视图中通过// These are ready to be copied into an AudioBufferSourceNode's channel data.
var theWavDataInFloat32;
function floatTo16Bit(inputArray, startIndex){
var output = new Uint16Array(inputArray.length-startIndex);
for (var i = 0; i < inputArray.length; i++){
var s = Math.max(-1, Math.min(1, inputArray[i]));
output[i] = s < 0 ? s * 0x8000 : s * 0x7FFF;
}
return output;
}
// This is passed in an unsigned 16-bit integer array. It is converted to a 32-bit float array.
// The first startIndex items are skipped, and only 'length' number of items is converted.
function int16ToFloat32(inputArray, startIndex, length) {
var output = new Float32Array(inputArray.length-startIndex);
for (var i = startIndex; i < length; i++) {
var int = inputArray[i];
// If the high bit is on, then it is a negative number, and actually counts backwards.
var float = (int >= 0x8000) ? -(0x10000 - int) / 0x8000 : int / 0x7FFF;
output[i] = float;
}
return output;
}
// TEST
var data = [ 65424, 18, 0, 32700, 33000, 1000, 50000 ];
var testDataInt = new Uint16Array(data);
var testDataFloat = int16ToFloat32(testDataInt, 0, data.length);
var testDataInt2 = floatTo16Bit(testDataFloat, 0);
// At this point testDataInt2 should be pretty close to the original data array (there is a little rounding.)
var xhr = new XMLHttpRequest();
xhr.open('GET', '/my-sound.wav', true);
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
if (this.status === 200) {
// This retrieves the entire wav file. We're only interested in the data portion.
// At the beginning is 44 bytes (22 words) of header, and at the end is some metadata about the file.
// The actual data length is held in bytes 40 - 44.
var data = new Uint16Array(this.response);
var length = (data[20] + data[21] * 0x10000) / 2; // The length is in bytes, but the array is 16 bits, so divide by 2.
theWavDataInFloat32 = int16ToFloat32(data, 22, length);
}
};
xhr.send();
将其设为隐藏字段。
请勿对密码执行此操作。实际上,您无论如何都无法呈现密码,因为您应该只有一个单向加密副本。