English 中文(简体)
MVC 3 隐藏字段
原标题:MVC 3 Hidden Fields

我通过“ViewModel”的中介机构,对一些与我的模型相连的非常长的视角进行了非常努力的工作。我的模型是一个单独的项目。

所有工作都很好,但有些字段是我想隐藏的视野。我大部分都用过,像这样的东西:

        <td id="Left">@Html.LabelFor(x=>x.Id)</td>
        <td id="Right">@Html.TextBoxFor(model => model.Id)</td>

迄今所有田地的面积(每处有几百个田地),

我不得不进入这些 并改变其中的很多 隐藏,因为我不得不在很多地方这样做。

我想知道是否有选择 把它置于视觉模型的属性之上 比如:

    [Display(Name = "ID:")]
    [HiddenInput(DisplayValue = false)]
    public int Id { get; set; }

以便同时隐藏标签和输入文本框, 所以只有我标记的字段出现。 我认为我应该能够设置一个属性来这样做, 这样我哪里出错了 。

提前感谢任何帮助。

最佳回答

不,在你的情况,没有 出箱的解决方案。

http://msdn.microsoft.com/en-us/library/system.com/ en-us/library/ system. supplicationmodel. dataannotations. dataannotos. scafoldcolumnlunatripte" rel="nofolt" rel= "nofolt" > ScafoldColumnAttripitte 控制了输入和标签的生成,但只有在使用 动态生成的视图 < / em >, 使用 < code> EditorForModel 时才能在行动中看到。 这种技术完全删除了 html, 这与生成隐藏的输入并不相同。

您可以尝试使用 jQuery 和 < a href=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

<script>
$(function () {
    $( input[name$="Id"] ).closest( tr ).hide();
});
</script>
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...