如下方法调用RenderPartial:

报“No overload for method 'Write' takes 0 arguments”的错误;

@if (@Model != null && @Model.ProductBaseInfo != null)

}
else
{
@Html.Partial("PartialView/_ProductNotFound")
}

@if (@Model != null && @Model.ProductBaseInfo != null)
{ }
else
{ @{Html.RenderPartial("PartialView/_ProductNotFound");}
}

改为下面代码后错误消失:

@if (@Model != null && @Model.ProductBaseInfo != null)
{ }
else
{ @Html.Partial("PartialView/_ProductNotFound")
}

网上找了一下资料:http://www.cnblogs.com/meen/p/3145696.html

下面的第一条应该解释了原因:RenderPartial和@Html.Partial一种是直接输出Html,一种是在内部输出(RenderPartial),所以RenderPartial无法直接生成Html。

1、带有Render的方法返回值是void,在方法内部进行输出;不带的返回值类型为MvcHtmlString,所以只能这样使用:
    @Html.Partial 对应 @{Html.RenderPartial(....);}
    @Html.Action 对应 @{Html.RenderAction(....);}

2、Action、RenderAction加载方法的视图,执行Controller → Model → View的顺序,然后把产生的页面带回到原来的View中再回传。而Partial、RenderPartial直接加载视图文件内容

3.  Html.Partial可以直接提供用户控件名作为参数,而Html.Action需要有对应的Action,在Action内部返回PartailResult(即retun PartialView())。

4、对于简单的没有任何逻辑的用户控件,推荐使用Html.Partial;对于需要设置一些Model的用户控件,推荐使用Html.Action。当然,有Model数据也是可以使用Html.Partial方法的,可以看方法的重载。

5、使用Html.Action有个好处,就是可以根据不同的场景选择不同的用户控件。比如:
@Html.Action("UserInfoControl")
在对应的UserInfoControl这个Action中,在用户未登录的时候,可以retun PartialView("LogOnUserControl");登录后,可以retun PartialView("UserInfoControl");

RenderPartial: No overload for method 'Write' takes 0 arguments的更多相关文章

  1. C# "error CS1729: 'XXClass' does not contain a constructor that takes 0 arguments"的解决方案

    出现这种错误的原因时,没有在子类的构造函数中指出仅有带参构造函数的父类的构造参数. 具体来讲就是: 当子类要重用父类的构造函数时, C# 语法通常会在子类构造函数后面调用 : base( para_t ...

  2. Matlab无法打开M文件的错误( Undefined function or method 'uiopen' for input arguments of type 'char)

    错误提示: Undefined function or method 'uiopen' for input arguments of type'char 解决方案: 运行命令 restoredefau ...

  3. Base class does not contain a constructor that takes '0' argument

    刚刚在写一段直播室网站中的一段程序遇,突然遇到一个错误,如下 'TVLLKBLL.BaseClass' does not contain a constructor that takes 0 argu ...

  4. 已解决:Strict Standards: Non-static method cls_image::gd_version() should not be called statically in...

    在安装Ecshop的时候,遇到两个⚠️问题: Strict Standards: Non-static method cls_image::gd_version() should not be cal ...

  5. MyBatis3.4.0以上的分页插件错误:Could not find method on interface org.apache.ibatis.executor.statement.StatementHandler named prepare. Cause: java.lang.NoSuchMethodException: org.apache.ibatis.executor.stateme

    错误: Could not find method on interface org.apache.ibatis.executor.statement.StatementHandler named p ...

  6. MyBatis与Spring MVC结合时,使用DAO注入出现:Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

    错误源自使用了这个例子:http://www.yihaomen.com/article/java/336.htm,如果运行时会出现如下错误: Invocation of init method fai ...

  7. C++版 - 剑指Offer 面试题45:圆圈中最后剩下的数字(约瑟夫环问题,ZOJ 1088:System Overload类似)题解

    剑指Offer 面试题45:圆圈中最后剩下的数字(约瑟夫环问题) 原书题目:0, 1, - , n-1 这n个数字排成一个圈圈,从数字0开始每次从圆圏里删除第m个数字.求出这个圈圈里剩下的最后一个数字 ...

  8. scala - multiple overloaded alternatives of method bar define default arguments

    同名同位置默认参数不能overload def bar(i:Int,s:String="a"){} def bar(i:String,s:String="b") ...

  9. Method not found: !!0[] System.Array.Empty()错误

    最近由于公司项目需要将之前支持的TLS1.0改成更安全的TLS1.2,而公司现有项目都是老系统,有的是.NET FrameWork 4.0,有的是.NET FrameWork3.5,但是TLS1.2默 ...

随机推荐

  1. 理解Java的GC日志

    分析如下GC日志:[GC [PSYoungGen: 9216K->1024K(9216K)] 1246196K->1246220K(1287040K), 0.2398360 secs] [ ...

  2. html中的表格 bootstrap-table

    1 bootstrap-table 官网: http://bootstrap-table.wenzhixin.net.cn/ 2

  3. mysql插入返回当前生成的主键

     1:sql中需要添加属性 keyColumn="base_price_id" keyProperty="basePriceId" useGeneratedKe ...

  4. j2ee基础

    1.tomcat端口被占用解决方式 使用netstat -anb查看哪个进程占用,禁止掉 修改tomacat使用的端口,在配置文件conf/server.xml 2.web app目录 3.如何建立虚 ...

  5. nginx,php日志分割

    作者:zhanhailiang 日期:2014-01-06 默认nginx只会生成一个access.log和一个error.log,并且每天不断积累,日志文件会变的非常大,如果需要做一下日志的分析,无 ...

  6. 变态最大值(nyoj)

    变态最大值 描述 Yougth讲课的时候考察了一下求三个数最大值这个问题,没想到大家掌握的这么烂,幸好在他的帮助下大家算是解决了这个问题,但是问题又来了. 他想在一组数中找一个数,这个数可以不是这组数 ...

  7. codeforces 518A. Vitaly and Strings

    A. Vitaly and Strings time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. python 序列类型

    1.不可变的序列类型:tuple.range.str.set 001:对于tuple 类型有如下几种构造方式 1.() 构造一个空的元组. 2.a | (a,) 构造一个只有一个元素的元组. 3.tu ...

  9. SQL Server 内存使用量下降问题

    SQL server这个程序是非喜欢内存这东西的.所以它的内存使用量下降,一定是被别人给抢去了.这件事的后果就是SQL Server 变的 非常慢.怎么样才可以让这件事不太容易发生呢? ------- ...

  10. BCB的博客,以及例子(好多传输文件的例子)

    http://blog.csdn.net/keyu1711/ http://download.csdn.net/user/keyu1711 http://download.csdn.net/user/ ...