RenderPartial: No overload for method 'Write' takes 0 arguments
如下方法调用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的更多相关文章
- C# "error CS1729: 'XXClass' does not contain a constructor that takes 0 arguments"的解决方案
出现这种错误的原因时,没有在子类的构造函数中指出仅有带参构造函数的父类的构造参数. 具体来讲就是: 当子类要重用父类的构造函数时, C# 语法通常会在子类构造函数后面调用 : base( para_t ...
- 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 ...
- Base class does not contain a constructor that takes '0' argument
刚刚在写一段直播室网站中的一段程序遇,突然遇到一个错误,如下 'TVLLKBLL.BaseClass' does not contain a constructor that takes 0 argu ...
- 已解决: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 ...
- 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 ...
- 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 ...
- C++版 - 剑指Offer 面试题45:圆圈中最后剩下的数字(约瑟夫环问题,ZOJ 1088:System Overload类似)题解
剑指Offer 面试题45:圆圈中最后剩下的数字(约瑟夫环问题) 原书题目:0, 1, - , n-1 这n个数字排成一个圈圈,从数字0开始每次从圆圏里删除第m个数字.求出这个圈圈里剩下的最后一个数字 ...
- 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") ...
- Method not found: !!0[] System.Array.Empty()错误
最近由于公司项目需要将之前支持的TLS1.0改成更安全的TLS1.2,而公司现有项目都是老系统,有的是.NET FrameWork 4.0,有的是.NET FrameWork3.5,但是TLS1.2默 ...
随机推荐
- crontab指令详解
引用:http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/06/3002602.html 具体指令请参考文章:linux指令. 详细版推荐原 ...
- Windows 端口和任务 查看 相关命令
netstat -aon|findstr " //查看端口 tasklist|findstr " //根据PID找到对应的程序 taskkill /f /t /im netbox. ...
- mysql三张表关联查询
三张表,需要得到的数据是标红色部分的.sql如下: select a.uid,a.uname,a.upsw,a.urealname,a.utel,a.uremark, b.rid,b.rname,b. ...
- MysqlDataSource里的Connection实现类实现了isValid(int timeout)方法
在项目中,需要连接mysql数据库的时候,我们最好选择使用数据库连接池,即需要选择DataSource. 而在使用c3p0的ComboPooledDataSource时,发现它的Connection实 ...
- 【Lucene4.8教程之二】索引
一.基础内容 0.官方文档说明 (1)org.apache.lucene.index provides two primary classes: IndexWriter, which creates ...
- jdbc之二:DAO模式
详细代码请参见 https://code.csdn.net/jediael_lu/daopattern 1.创建Dao接口. package com.ljh.jasonnews.server.dao; ...
- JDBC之一:JDBC快速入门
(1)下载Oracle的JDBC驱动,一般放在$ORACLE_HOME/jdbc/lib目录,关于驱动的版本请见: http://elf8848.iteye.com/blog/811037 随Orac ...
- JS数组删除一个元素(根据值删)
<script type="text/javascript"> <!-- // 删除数组中第一个匹配的元素,成功则返回位置索引,失败则返回 -1. Array.p ...
- 关于left join连接查询 两张表里有同名字段的问题
左连接查询在开发中很常用,但有个问题常常会遇到,两个表中有同名字段时,比如左右表都有一个id字段,会造成查询结果中左表的id值被右表的id值覆盖掉(大部分php框架都是这个效果),而且还不会报错,容易 ...
- SQL Server 引起磁盘IO的原因
1. 要访问的数据不在内存中.这会引起IO 2. update/delete/insert 会把变化写入数据文件.还要记录日志 : 3. checkpoint 4. lazy writer 5. db ...