传递到字典中的模型产品类型“my_photos.Models.profile'的,但需要输入”my_photos.Models._partial [英] the model item passed into the dictionary is of type 'my_photos.Models.profile', but need type 'my_photos.Models._partial

查看:135
本文介绍了传递到字典中的模型产品类型“my_photos.Models.profile'的,但需要输入”my_photos.Models._partial的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我更新我的问题有这么一个人能拿那边什么我的应用程序究竟发生有更多的细节,我告诉你我是新与.NET MVC环境。所以这是我的变化我创造我的一些应用程序在它。我已经创建了三款车型首次有他们在的地方仪式的地方。当我从局部视图的应用程序发表评论模型运行正常。但是,如果我去掉模型应用返回以下错误。 [InvalidOperationException异常:局部视图〜/查看/共享/ Partial.cshtml未找到或没有视图引擎支持搜索到的位置。以下地点被搜查
这里是我的_layout.cshtml文件。

hi there i am updating my question there so someone could get more details over there what exactly happening there in my app as i told you i am new with the .net mvc environment. so this is my vary first time that i am creating some of my app in it.i have created three models and have place them in the rite place. when i comment model from the partial view application runs fine. but if i uncomment the model application return the following error. [InvalidOperationException: The partial view '~/Views/Shared/Partial.cshtml' was not found or no view engine supports the searched locations. The following locations were searched here is my _layout.cshtml file.

    @model my_photos.Models._partial
    @{
        Layout = null; 
    }
    <!DOCTYPE html>

    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>_Layout</title>
        <link href="@Url.Content("~/Content/Style/Site.css")" rel="stylesheet" type="text/css" />
        <link href="@Url.Content("~/Content/Style/Side_barnav.css")" rel="stylesheet" type="text/css" />


    </head>
        <body>
            <header>
                <h3> Photos app</h3>
                <p> In this app my major concerns are with the <strong>theaming</strong>!</p>
                <div class="nav">
                <ul class="main-menu">
                    <li>@Html.ActionLink("Home","Index", "Default")</li>
                    <li>@Html.ActionLink("About","About", "Default")</li>
                    <li>@Html.ActionLink("Contact","Contact", "Default")</li>
                </ul>
                </div>
            </header>
        <section>
                @RenderBody()
                @Html.Partial("~/Views/Shared/_partial.cshtml", Model)
        </section>
            <footer>
            <div class="fotter-menu">
                <ul>
                    <li>@Html.ActionLink("Home","Index","Default")</li>
                    <li>@Html.ActionLink("About","About","Default")</li>
                    <li>@Html.ActionLink("Contact","Contact","Default")</li>
                </ul>
                <ul>
                    <li>@Html.ActionLink("Resources","Resources","Default")</li>
                    <li>@Html.ActionLink("Testimonial","Testimonial","Default")</li>
                    <li>@Html.ActionLink("Team","Team","Default")</li>
                </ul>
                <ul>
                    <li>@Html.ActionLink("Home","Index","Default")</li>
                    <li>@Html.ActionLink("Home","Index","Default")</li>
                    <li>@Html.ActionLink("Home","Index","Default")</li>
                </ul>
            </div>
        </footer>
    </body>
</html>

和这里是我的主控制器文件。

and here is my main controller file.

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


namespace my_photos.Controllers
{
    public class DefaultController : Controller
    {


        public ActionResult Index()
        {
            ViewBag.Massage = "Hello Word";
            var Profile = new profile() { 
                name = "Aston",
                father_name = "Johan Deoh",
                address = " XYZ XYZ XYZ XYZ",
                Phone = "123123123",
                age = 22
            };

            return View(Profile);
        }
        public ActionResult About() {

            var aboutus = new about() {
                Us = "this is all i got by the way"
            };
            return View(aboutus);
        }


        public ActionResult _partial()
        {
            var model = new _partial() { 
                Winner = "Shafee Jan"
            };
            return PartialView("_partial",model);
        }

    }
}

下面是我的有关文件。

@model my_photos.Models.about
@{
    ViewBag.Title = "About";
}
 <div class="content-container clear-fix">
    <h1 class="heading-width">About-Page</h1>
    <p class="paragraph"> 
        @Model.Us
    </p>
</div>

下面是我的index.cshtml

Here is my index.cshtml

@model my_photos.Models.profile
@{
    ViewBag.Title = "Index"; 
}
<div class="content-container clear-fix">
    <h1 class="heading-width">Names </h1>
    <ul>
        <li> name @Model.name.ToString()</li>
        <li> father name: @Model.father_name.ToString()</li>
    </ul>
</div>

下面是我的模型

public class _partial
{
    public string Winner { get; set; }
}

public class about
{
    public string Us { get; set; }
}

public class profile
{
    public String name { get; set; }
    public String father_name { get; set; }
    public String Phone { get; set; }
    public String address { get; set; }
    public String Status { get; set; }
    public int age { get; set; }
}

当过我运行这个code返回:

when ever i run this code it returns:

传递到字典的模型项的类型是my_photos.Models.profile',但本词典需要类型的my_photos.Models._partial的典范项目。

The model item passed into the dictionary is of type 'my_photos.Models.profile', but this dictionary requires a model item of type 'my_photos.Models._partial'.

好心帮我

推荐答案

使用HTML操作

Use  @Html.Action("_partial", "Controler");

这篇关于传递到字典中的模型产品类型“my_photos.Models.profile'的,但需要输入”my_photos.Models._partial的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆