English 中文(简体)
ASP.NET MVC有生成唯一ClientIDs的方式吗?
原标题:Does ASP.NET MVC have a way to generate unique ClientIDs?

在ASP.NET MVC中是否有创建唯一“id”标签的开箱即用方式?

(与网络版面广但有时是有用的用户信息?)

当在页面上多次呈现部分视图时,这将非常有用。

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%-- Example Partial View --%>
<div id="<%=GenerateAUniqueIDHere()%>">
Content
</div>
<script type="text/javascript">
    $("#<%=GenerateAUniqueIDHere%>").hide().fadein().css("font-size", "500%");
</script>

如果不行,那么自己制作也很容易。

非常感谢。

乔恩

问题回答

使用GUID?

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> 
<%-- Example Partial View --%> 
<%
    string ID = Guid.NewGuid().ToString();
%>
<div id="<%=ID%>"> 
    Content 
</div> 
<script type="text/javascript"> 
    $("#<%=ID%>").hide().fadein().css("font-size", "500%"); 
</script>

我还会在渲染部分方法调用时将GUID作为视图数据对象传递,以保持您的ViewUserControl整洁。

我知道,科索沃失踪人员调查委员会没有这样做。 我已经使用了伙伴关系。 NET MVC已有一年多时间,从未使用过。 当我有几次控制,名称相同时,我几乎总是想稍后能够质疑这些控制,因此,我需要知道伊德,并使用反面,所以我知道这些名字。 如果你不需要知道他们的孩子,那么为什么甚至给他们一个id?





相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签