如何使用Razor视图引擎在ASP.NET MVC3中创建只读文本框?是否有HTMLHelper方法可以做到这一点?
像这样的东西?
__CODE__
MutableSlab和ImmutableSlab实现之间的唯一区别是readonly应用于handle字段的修饰符:
using System;
using System.Runtime.InteropServices;
public class Program
{
class MutableSlab : IDisposable
{
private GCHandle handle;
public MutableSlab()
{
this.handle = GCHandle.Alloc(new byte[256], GCHandleType.Pinned);
}
public bool IsAllocated => this.handle.IsAllocated;
public void Dispose()
{
this.handle.Free();
}
}
class ImmutableSlab : IDisposable
{
private readonly GCHandle handle;
public ImmutableSlab()
{
this.handle = GCHandle.Alloc(new byte[256], GCHandleType.Pinned);
}
public bool IsAllocated => this.handle.IsAllocated;
public void Dispose()
{
this.handle.Free();
}
}
public static void Main()
{ …Run Code Online (Sandbox Code Playgroud) 我想在python中创建一个具有一些属性的对象,我想保护自己不会意外使用错误的属性名称.代码如下:
class MyClass( object ) :
m = None # my attribute
__slots__ = ( "m" ) # ensure that object has no _m etc
a = MyClass() # create one
a.m = "?" # here is a PROBLEM
Run Code Online (Sandbox Code Playgroud)
但运行这个简单的代码后,我得到一个非常奇怪的错误:
Traceback (most recent call last):
File "test.py", line 8, in <module>
a.m = "?"
AttributeError: 'test' object attribute 'm' is read-only
Run Code Online (Sandbox Code Playgroud)
有没有明智的程序员能够节省一些时间并让我了解"只读"错误?
你知道一种使HTML输入表单字段使用WTForms的'readonly'属性的方法吗?
我有一个具有各种公共属性的类,我允许用户通过属性网格进行编辑.对于持久性,此类还通过DataContractSerializer与XML文件进行序列化/反序列化.
有时我希望用户能够将他们所做的更改保存(序列化)到类的实例中.但在其他时候,我不想让用户保存他们的更改,而应该将属性网格中的所有属性都看作只读.我不想让用户进行以后永远无法保存的更改.类似于MS Word将允许用户打开当前由其他人打开但仅作为只读的文档.
我的类有一个布尔属性,用于确定该类是否应该是只读的,但是是否可以使用此属性以某种方式在运行时动态地向类属性添加只读属性?如果不是什么是替代解决方案?我应该将我的类包装在只读包装类中吗?
使用Ace代码编辑器,我可以锁定或只读一段代码,但仍允许在会话期间编写或编辑其他代码行吗?
考虑到Python的动态性,如果不可能的话,我会感到震惊:
我想改变执行情况sys.stdout.write.
我从这个答案得到了我的另一个问题的想法:https://stackoverflow.com/a/24492990/901641
我试着写这个:
original_stdoutWrite = sys.stdout.write
def new_stdoutWrite(*a, **kw):
original_stdoutWrite("The new one was called! ")
original_stdoutWrite(*a, **kw)
sys.stdout.write = new_stdoutWrite
Run Code Online (Sandbox Code Playgroud)
但它告诉我AttributeError: 'file' object attribute 'write' is read-only.
这是一个很好的尝试,让我不要做一些潜在的(可能)愚蠢的事情,但我真的很想继续这样做.我怀疑解释器有一些我可以修改的查找表,但我在Google上找不到类似的东西.__setattr__也没用 - 它返回了关于属性为只读的完全相同的错误.
我特意寻找Python 2.7解决方案,如果这很重要,虽然没有理由拒绝投入适用于其他版本的答案,因为我怀疑未来的其他人会在这里看到与其他版本类似的问题.
我正在使用react bootstrap,这个框架提供了一些不错的FormControls.
但是我想使FormControls中生成的Input字段具有readonly ="readonly"的prop.这样,此字段看起来与我的其他FormControls相同,但不在IOS上提供键盘输入.
在我的情况下,输入将由日历选择器提供,该日历选择器将由弹出窗口触发.
有谁知道如何给FormControl参数readonly ="readonly",以便浏览器中生成的输入字段将具有read readlyly ="readonly"?
很多thnx的答案!
我有一个简单的类,我想在构造函数启动的方法中为只读属性赋值,但它说[ts] Cannot assign to 'readOnlyProperty' because it is a constant or a read-only property.
为什么即使我process从构造函数调用,我也不能为属性赋值?
示例代码:
class C {
readonly readOnlyProperty: string;
constructor(raw: string) {
this.process(raw);
}
process(raw: string) {
this.readOnlyProperty = raw; // [ts] Cannot assign to 'readOnlyProperty' because it is a constant or a read-only property.
}
}
Run Code Online (Sandbox Code Playgroud) c# ×4
python ×3
.net ×1
ace-editor ×1
class ×1
constructor ×1
descriptor ×1
editor ×1
exception ×1
form-control ×1
forms ×1
html ×1
html-helper ×1
python-2.7 ×1
razor ×1
reactjs ×1
stdout ×1
struct ×1
typescript ×1
value-type ×1
wtforms ×1