微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

遇到有关编译我的项目的问题

如何解决遇到有关编译我的项目的问题

任何人都可以针对所附图像中遇到的以下问题为我提供帮助。我正在尝试转到以下URL:http:// localhost:49849 / Customers,但我不能。在此先感谢...只是为了让您知道我正在跟踪莫什的课程。

enter image description here

这是型号代码

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;   //this is a namespace

namespace Vidly2.Models
{
    public class Customers
    {

        public int id { get; set; }
        [required] // we cal changing the conventions dataannotations
        [StringLength(255)]
        public string name { get; set; }
        public bool IsSubscribedToNewsletter { get; set; }
        public MembershipType MembershipType { get; set; } // we call it navigation property because it allows us to navigate to another type
        public byte MembershipTypeId { get; set; } //Fk
    }
}

这是控制器代码

using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Vidly2.Models;


namespace Vidly2.Controllers
{
    public class CustomersController : Controller
    {
        public ViewResult Index()
        {
            var customers = GetCustomers();

            return View(customers);
        }

        public ActionResult Details(int id)
        {
            var customer = GetCustomers().SingleOrDefault(c => c.id == id);

            if (customer == null)
                return HttpNotFound();

            return View(customer);
        }

        private IEnumerable<Customers> GetCustomers()
        {
            return new List<Customers>
            {
                new Customers { id =1,name = "John Smith" },new Customers { id =2,name = "Mary Williams" }
            };
        }
    }
}

这是查看代码,其中提到了有关编译项目的错误

@using System.Web.Mvc.Html;


@model IEnumerable<Vidly2.Models.Customers>
@*
    Note: I've set the model for this view to IEnumerable<Customer>.
    This is a simple interface implemented by the list class. Since
    in this view we only want to iterate over this list,and we don't
    need any of the operations in the List class (eg Add,Remove,etc),it's better to use the IEnumerable interface,which allows use to
    iterate over the list. If in the future,we replace the List with a
    different data structure,as long as it is enumerable,our view code
    will remain unchanged.
*@

@{
    ViewBag.Title = "Customers";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Customers</h2>
@if (!Model.Any())
{
    <p>We don't have any customers yet.</p>
}
else
{
    <table class="table table-bordered table-hover">
        <thead>
            <tr>
                <th>Customer</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var customer in Model)
            {
                <tr>
                    <td>@Html.ActionLink(customer.Name,"Details","Customers",new { id = customer.id },null)</td>
                </tr>
            }
        </tbody>
    </table>
}

解决方法

您有name的属性不匹配,就像模型中的情况一样,name在较小的情况下,但是鉴于您使用的customer.Name应该是customer.name >

@Html.ActionLink(customer.name,"Details",...

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。