Csharp/C#教程:asp.net c#生成用户控制参数分享


asp.net c#生成用户控制参数

ASP.net对我来说是新手,我已经交了一个现有项目。 我写了SO: Asp.Net WebForms – 如何将ViewData作为param传递给用户控件,但由于没有响应,我不能说清楚。

我想做这个:

Consignment.ascx: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>  <% var applicationId = ViewData["NoiId"]; var applicationSpecies = ViewData["applicationSpecies"] as HashSet; // Same as the JS var applicationSpecies but from server - needed to build page %> ...  <div id="_grid" style="display: none;"> <uc:speciesgrid runat="server" species=/> 

但它在<uc:speciesgrid <uc:speciesgrid了:

 {"Server tags cannot contain  constructs."} 

用户控制:

 SpeciesGridController.ascx      private IDictionary readRouteValueDictionary = new Dictionary(); private int _applicationId; private string _species; public string species { set { if (!value.IsEmpty()) { _species = value; readRouteValueDictionary.Add("species", value); } } get { return _species; } ... }  
<% Html.Kendo().Grid() .Name("grdNlsConsignment"+species) ... %>

如何让<uc:speciesgrid runat="server" species=/>工作?

感谢@Tetsuya Yamamoto的评论。 这就是我想出的。

我认为使用Code Behind对象时, SpeciesGridView.ascx会更好,而不是包含

上述就是C#学习教程:asp.net c#生成用户控制参数分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 Consignment.ascx <% var applicationId = ViewData["NoiId"]; var allSpecies = ViewData["allSpecies"] as List; %> ... <% foreach (ListItem speciesItem in allSpecies) { var species = speciesItem.Value.Replace(" ", "_");%>  <%}%> 

 SpeciesGridViewDTO.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization; namespace Daff.Lae.TraceCommon.DTO.NoiReproNLS { ///  /// This DataTransferObject is for sending a succinct model to the SpeciesGridView ///  [DataContract, Serializable] public class SpeciesGridViewDTO { [DataMember] public Int32 NoiId { get; set; } [DataMember] public String SpeciesCode { get; set; } public SpeciesGridViewDTO(int NoiId, string SpeciesCode) { this.NoiId = NoiId; this.SpeciesCode = SpeciesCode; } } } 

 SpeciesGridView.ascx <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl"%> <%@ Import Namespace="Daff.Lae.TraceCommon.ValueObjects" %> <%@ Import Namespace="Kendo.Mvc.UI" %> <%@ Import Namespace="Daff.Lae.TraceCommon.ValueObjects.NoiReproNLS" %> <%@ Import Namespace="System.Diagnostics" %> <%-- SpeciesGrid - render KendoGrid of NoiNlsConsignmentVO. --%>  
<%=Model.SpeciesCode%>
<% Html.Kendo().Grid() .Name("grdNlsConsignment"+Model.SpeciesCode) ...

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1027284.html

(0)
上一篇 2022年1月9日
下一篇 2022年1月9日

精彩推荐