无法对 null 引用执行运行时绑定
说明:
执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 无法对 null 引用执行运行时绑定
源错误:
视图,Demo.csthml:
@model LanhuImageUploader.Web.Models.Product
ViewBag.Title = "Demo";
@Html.Action("ScriptCommon", "Common")
<div
class
=
"pop-win"
>
<div
id
=
"check-order"
>
<div
class
=
"row"
style
=
"
margin-top
:
30px
;
"
>
<span
class
=
"field"
>
商品图片:
</span>
<span><input
type
=
"button"
class
=
"btn btn-primary"
style
=
"
padding-left
:
18px
;
"
value
=
"添加图片"
page
=
"ProImages"
onclick
=
"
addPageImg
(
this
)
"
/></span>
<input
type
=
"hidden"
id
=
"hidProImages"
name
=
"ADPicUrl"
value
=
"@Model.ADPicUrl"
/>
<input
type
=
"hidden"
id
=
"hidProImages"
name
=
"ADPicUrl"
value
=
""
/>
<div
class
=
"row"
>
<table
class
=
"produtImageThumb"
>
<tr
pre
=
"imgtr"
id
=
"imgtr-ProImages"
style
=
"
display
:
none
"
><td
colspan
=
"2"
></td></tr>
</table>
@Html.Action("UploadImage", "Common")
<script>
$
(
function
()
{
</script>
这种情况一般是返回视图的时候没有传model对象才会报错,如下:
public
ActionResult
Demo
()
return
View
();
解决办法:
在Action中当返回View的时候,传一个默认的model给它如下:
public
ActionResult
Demo
()
var
m
=
new
LanhuImageUploader
.
Web
.
Models
.
Product
();
return
View
(
m
);