如下方法调用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. Android 创建自定义布局

    我们所有的控件都是继承至View类的,而所有的布局都是继承至ViewGroup的,所以我们也可以继承某个view类来实现我们自己的布局或者控件. 引入布局 我们新建一个title.xml的layout ...

  2. 解决英文版Windows程序乱码

    前段时间由于工作需要装了一个英文版Windows,以至于在一些脚本和控制台程序里面处理汉字的时候总是显示乱码(比如:“???”). 在尝试了很多编码和解码的操作后,乱码问题还是没能很好的解决.后来才发 ...

  3. 移动网页版Meta 标签

    viewport 大部分移动浏览器都接受,比如 Opera Mobile, iPhone, Android, Iris, IE, BlackBerry, Obigo, Firefox 最基本的例子,在 ...

  4. apache配置gzip模式(转)

    最近在看有关提高website性能的书,个人觉得挺不错的两本书: <<high performance websites>> <<even faster websi ...

  5. C++有没有string转化int的函数,怎样转换

    有两种方法1. c++中string到int的转换 1) 在C标准库里面,使用atoi: #include <cstdlib>#include <string> std::st ...

  6. SQL Server identity种子

    背景: 用identity修饰列可以使它自动增长 例了: create table T(ID int not null identity(1,1),      Data nvarchar(32)); ...

  7. thinkPHP模板引擎案例

    1.if <if condition="$vo.business eq LS"> 零售 <elseif condition="$vo.business ...

  8. C#尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

    安装VS2013后,win7 + .net 4 + c#程序无法连接到SQL Server2000的实例 SQLServer2012在登录远程服务器实例时报错:尝试读取或写入受保护的内存. “尝试读取 ...

  9. 【LeetCode练习题】Candy

    分糖果 There are N children standing in a line. Each child is assigned a rating value. You are giving c ...

  10. H264源码分析(二)

    原文出自http://blog.csdn.net/xfding/article/details/5476763(转载收集) (四)图像参数集语义 pic_parameter_set_rbsp( ) { ...