English 中文(简体)
ASP. NET 部分观点和隐藏的变数与MVC 3(Razor)
原标题:ASP.NET partial views and hidden variables with MVC 3 (Razor)

在从《示范法》中产生隐藏的变量时,只使用变数名称。 如果使用该模型的带宽等级/结构,则使用类别/结构名称。 这有助于张贴表格,因为该系统更容易看到其填充的物体。

然而,在使用部分观点时,我常常通过该模式的某些部分,这意味着暗藏的田地不再有其固定的地段/地名。 这可能在重新确定员额参数时造成冲突或数据损失。 是否有任何办法获得Html。 隐蔽(或等同)把阶级/建筑名称放在前面?

问题回答

两种选择:

  1. 使用<代码>Html.EditorFor(>,而不是直截了部分。 编辑 考虑用来获取财产的前fix/eira,或

  2. 操纵 TemplateInfo.Html Field Prefix, 然后再将儿童部分纳入其中,这将导致儿童的每一领域自动得到确定。

如果您申请选择(2),考虑宣布一名助手,填写<代码>。 Html FieldPrefix 操纵,以防你重新制定(Iripped the Code for )。 Child PrefixScope below from some where others on some time before.

指称:

static public class MyHtmlHelpers
{
    public static IDisposable BeginChildScope<TModel>(this HtmlHelper<TModel> html, string parentScopeName)
    {
        return new ChildPrefixScope(html.ViewData.TemplateInfo, parentScopeName);
    }

    private class ChildPrefixScope : IDisposable
    {
        private readonly TemplateInfo _templateInfo;
        private readonly string _previousPrefix;

        public ChildPrefixScope(TemplateInfo templateInfo, string collectionItemName)
        {
            this._templateInfo = templateInfo;

            _previousPrefix = templateInfo.HtmlFieldPrefix;
            templateInfo.HtmlFieldPrefix = collectionItemName;
        }

        public void Dispose()
        {
            _templateInfo.HtmlFieldPrefix = _previousPrefix;
        }
    }

}




相关问题
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. ...

热门标签