小编jan*_*nnn的帖子

如何将变量声明为与c#中返回的方法相同的数据类型?

所以我是完全新的而不是c#,我没有想法试试这个.我花了几个小时研究,但还没有找到解决方案.

我的问题是函数getUpcomingDates():如何将变量声明myDatesgetAllDates方法返回的相同数据类型?

我试过的方法之一是:MyDate[] myDates = new getAllDates();但是我在getAllDates下面得到一条红线说:"这是一种方法,但用作类型."

这样做的正确方法是什么?

[WebMethod]
private MyDate[] getAllDates()
{
    System.Collections.ArrayList myDates = new System.Collections.ArrayList();
    MyDate thisDate;


    thisDate = new MyDate(DateTime.Parse("9/1/2011"),
                          "Get classes ready", "Begin of fall semester");
    myDates.Add(thisDate);

    thisDate = new MyDate(DateTime.Parse("1/1/2011"),
                          "New Year", "Happy 2011!");
    myDates.Add(thisDate);

    thisDate = new MyDate(DateTime.Parse("12/16/2011"),
                          "BUS ADM 531 Final Exam", "See study guide on course Web pages");
    myDates.Add(thisDate);

    return (MyDate[])myDates.ToArray(typeof(MyDate));
}

[WebMethod]
private MyDate[] getUpcomingDates()
{
    MyDate[] myDates = new getAllDates();
    System.Collections.ArrayList …
Run Code Online (Sandbox Code Playgroud)

c# methods

1
推荐指数
1
解决办法
90
查看次数

System.InvalidOperationException:序列不包含元素 [MVC]

我正在尝试根据参数获取产品列表。在产品描述列表 (Index.chtml) 中,当我单击产品描述时,我想转到仅列出具有该产品描述的产品的页面。

例如:如果我单击 Index.chtml 页面上的“Barstools”,我只想浏览 Browse.chtml 页面上的 barstools。

但我不断收到此错误:

Exception Details: System.InvalidOperationException: Sequence contains no elements

Source Error: 

Line 25:         {
Line 26:             // 
Line 27:             var productModel = productDB.ProductDess.Include("Products")
Line 28:                 .Single(p => p.productDesName == productD);
Line 29:             return View(productModel);
Run Code Online (Sandbox Code Playgroud)

这是我所拥有的:

楷模::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::


产品.cs


[Table("Product")]
[Bind(Exclude = "productID")]
public class Product
{
    [ScaffoldColumn(false)]
    [Key]
    public string productID { get; set; }
    public string productName { get; set; }
    public string productDim { get; set; }
    public string productWoodSp{ …
Run Code Online (Sandbox Code Playgroud)

model-view-controller asp.net-mvc

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

asp.net-mvc ×1

c# ×1

methods ×1

model-view-controller ×1