TextBoxFor - 显示错误值 [英] TextBoxFor - Showing Wrong Value
问题描述
好吧,我在这里有一个奇怪的。我知道这个值被传递给正确的财产,因为这工作得很好:
Ok, I've got a weird one here. I know the value is being passed to the property correctly as this works fine:
@Html.TextBox("Foo", Model.Foo, new { @class = "bar" })
现在,如果我这样做:
@Html.TextBoxFor(m => m.Foo, new { @class = "bar" })
这表明是一个不正确的值。我绝对不知道在哪里这个值是从哪里来的。在一些网页上,它显示的应该是什么小写版本,其他时候,就说明它旁边的文本框的值。我很困惑。这是,这是否唯一的文本框。我也有使用这个精确的数值来显示页面的标题页面上的剃刀帮手,并且正确地显示。
It show's an incorrect value. I have absolutely no idea where this value is coming from. For some pages, it shows a lowercase version of what it should be, other times, it shows the value of the textbox next to it. I'm baffled. It's the only textbox that does this. I also have a razor helper on the page that uses this exact value to display the heading of the page, and that shows correctly.
我不介意使用 @ Html.TextBox()
为这个特殊的一个,但我想获得这条底线。
I don't mind using @Html.TextBox()
for this particular one, but I'd like to get the bottom of this.
别人有什么样随机发生的?我有这个特定页面上相当多的控制,它是唯一一个发生这种情况。
Anyone else had anything random like this happen? I have quite a few controls on this particular page and it's the only one this happens to.
推荐答案
哦,天啊......我刚刚发现的罪魁祸首。它的URL路径选择价值!笑
Oh jeez... I just found the culprit. It's the url routing value! lol
在我的全局文件,我不得不 {事} / {无论} / {ID} / {富}
, {富}
是一个可选的参数那里只是为了使页面看起来网址人类友好。
In my global file, I had {something}/{whatever}/{id}/{foo}
, {foo}
being an optional parameter there just to make the page url look human friendly.
有趣的是,在TextBoxFor使用的前pression从网址,而非视图模型牵引。我还以为它会读取之前将URL中的模式?即使是从智能感知模型拉。这是某种错误的?
It is interesting that the expression used in TextBoxFor is pulling from the URL rather than the viewmodel. I would have thought it'd read the model before going to the URL? Even intellisense pulls from the model. Is this some sort of a bug?
请注意自我:始终确保属性有不同的名称
Note to self: Always make sure properties have different names!
希望这经验将帮助别人。
Hopefully this experience will help others.
这篇关于TextBoxFor - 显示错误值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!