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; } ... }
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; } } }