开发者

The type or namespace name 'DinnerForm' does not exist in the namespace 'NerdDinner.Models' when trying to implement partial form

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0234: The type or namespace name 'DinnerForm' does not exist in the namespace 'NerdDinner.Models' (are you missing an assembly reference?)

Source Error:

Line 170:

Line 171: [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()] Line 172: public class views_dinners_create_aspx : System.Web.Mvc.ViewPage, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler { Line 173:

Line 174: private static bool @__initialized;

DinnerFormViewModel.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NerdDinner.Controllers;



namespace NerdDinner.Models
{
public class DinnerFormViewModel
{
    // Properties
    public Dinner Dinner { get; private set; }
    public SelectList Countries { get; private set; }

    // Constructor
    public DinnerFormViewModel(Dinner dinner)
    {
        Dinner = dinner;
        Countries = new SelectList(PhoneValidator.Countries, dinner.Country);
    }
}
}

DinnerForm.ascx:

<%@ Control Language="C#"       Inherits="System.Web.Mvc.ViewUserControl<NerdDinner.Controllers.DinnerFormViewModel>" %>

<%= Html.ValidationSummary("Please correct the errors and try again.") %>

<% using (Html.BeginForm()) { %>

<fieldset>
<p>
<label for="Title">Dinner Title:</label>
<%= Html.TextBox("Title", Model.Dinner.Title) %>
<%=Html.ValidationMessage("Title", "*") %>
</p>
<p>
<label for="EventDate">Event Date:</label>
<%= Html.TextBox("EventDate", Model.Dinner.EventDate) %>
<%= Html.ValidationMessage("EventDate", "*") %>
</p>
<p>
<label for="Description">Description:</label>
<%= Html.TextArea("Description", Model.Dinner.Description) %>
<%= Html.ValidationMessage("Description", "*") %>
</p>
<p>
<label for="Address">Address:</label>
<%= Html.TextBox("Address", Model.Dinner.Address) %>
<%= Html.ValidationMessage("Address", "*") %>
</p>
<p>
<label for="Country">Country:</label>
<%= Html.DropDownList("Country", Model.Countries) %>               
<%= Html.ValidationMessage("Country", "*") %>
</p>
<p>
<label for="ContactPhone">Contact Phone #:</label>
<%= Html.TextBox("ContactPhone", Model.Dinner.ContactPhone) %>
<%= Html.ValidationMessage("ContactPhone", "*") %>
</p>

<p>
<input type="submit" value="Save"/>
</p>
</fieldset>

<% } %>

DinnersControllers.cs (create methods)

//
// GET: /Dinners/Create

    public ActionResult Create()
    {

        Dinner dinner = new Dinner()
        {
            EventDate = DateTime.Now.AddDays(7)
        };
        return View(new DinnerFormViewModel(dinner));
    }

    //
    // POST: /Dinners/Create

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Create(Dinner dinner)
    {

        if (ModelState.IsValid)
        {

            try
            {
                dinner.HostedBy = "SomeUser";

                dinnerRepository.Add(dinner);
                dinnerRepository.Save();

                return RedirectToAction("Details", new { id = dinner.DinnerID });
            }
            catch
            {
                foreach (var issue in dinner.GetRuleViolations())
                {
                    ModelState.AddModelError(issue.PropertyName, issue.ErrorMessage);
                }

                return View(new DinnerFormViewModel(dinner));
            }
        }

        return View(new DinnerFormViewModel(dinner));
    }

Create.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"   Inherits="System.Web.Mvc.ViewPage<NerdDinner.Models.DinnerForm>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="serv开发者_如何学运维er">
Host A Dinner
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h2>Host a Dinner</h2>

<% Html.RenderPartial("DinnerForm"); %>
</asp:Content>


DinnerForm.ascx:

Inherits="System.Web.Mvc.ViewUserControl<NerdDinner.Models.DinnerFormViewModel>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜