C# Can';t从ASP.net-C获取模型属性#
我有一个完全由模型完成的表单,但是我不能得到一些属性,因为我相信在这个时刻,模型是空的。问题是,当我使用C# Can';t从ASP.net-C获取模型属性#,c#,asp.net,asp.net-mvc,asp.net-mvc-4,razor,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Razor,我有一个完全由模型完成的表单,但是我不能得到一些属性,因为我相信在这个时刻,模型是空的。问题是,当我使用@Model.someattribute时,它不起作用,但使用m=>m.cantidadMensajes时,它起作用。我需要知道为什么会发生这样的事,我该如何处理 @model SeaConnectionManager.Modelos.EnvioMensajes.InformacionEntity @{ var previsualizaciones = ""; if (@Model
@Model.someattribute
时,它不起作用,但使用m=>m.cantidadMensajes
时,它起作用。我需要知道为什么会发生这样的事,我该如何处理
@model SeaConnectionManager.Modelos.EnvioMensajes.InformacionEntity
@{ var previsualizaciones = "";
if (@Model != null) {
previsualizaciones = @Model.vistaPrevia;
}
}
<div id="Envio" class="overlay">
<div class="popup">
<h2 align="center">Información del Envío</h2>
<a class="close" href="#">×</a>
<div class="content" style="width:100%; margin:auto; padding:10px">
<center>
<a id="tabs">
<ul>
@if (@Model != null) {
if (@Model.cantidadMensajes >= 5)
{
for (var i = 1; i <= 5; i++)
{
<li><a href="#tabs-@i"> @i</a></li>
}
}
else {
for (var i = 1; i <= @Model.cantidadMensajes; i++)
{
<li><a href="#tabs-@i"> @i</a></li>
}
}
}
</ul>
@previsualizaciones
</div>
<table width="100%" border="0" align="center" cellspacing="4">
<tr>
<td width="36%">Cantidad de mensajes</td>
<td width="44%">
@Html.TextBoxFor(m => m.cantidadMensajes, new { @id = "CantidadMensajes", @class = "input-login", @readonly = "readonly" })
</td>
</tr>
<tr>
<td>Cantidad de contactos</td>
<td>
@Html.TextBoxFor(m => m.cantidadContactos, new { @id = "CantidadContactos", @class = "input-login", @readonly = "readonly" })
</td>
</tr>
<tr>
<td>Saldo</td>
<td>
@Html.TextBoxFor(m => m.saldo, new { @id = "Saldo", @class = "input-login", @readonly = "readonly" })
@Html.HiddenFor(m => m.idTransaccion, new { @id = "idTransaccion" })
</td>
</tr>
</table>
</center><br>
<center>
<table width="122" border="0" align="center" cellspacing="10">
<tr>
<td width="51"><a onclick="EnviarMensajes()" class="boton-para-enviar" style="margin:auto">Aprobar</a></td>
<td width="37"><a href="#" class="boton-para-NO-enviar" style="margin:auto">Rechazar</a></td>
</tr>
</table>
</center>
@model SeaConnectionManager.Modelos.enviromesajes.InformacionEntity
@{var previsualizaciones=”“;
如果(@Model!=null){
previsualizaciones=@Model.vistaPrevia;
}
}
环境和国际信息中心;o
}
}
否则{
对于(var i=1;i m.cantidadMensajes,new{@id=“cantidadMensajes”、@class=“input login”、@readonly=“readonly”})
康蒂达德酒店
@TextBoxFor(m=>m.cantidadContactos,新的{@id=“cantidadContactos”,@class=“input login”,@readonly=“readonly”})
萨尔多
@TextBoxFor(m=>m.saldo,新的{@id=“saldo”,@class=“input login”,@readonly=“readonly”})
@HiddenFor(m=>m.idTransaccion,new{@id=“idTransaccion”})
在没有运气的情况下,遵循一些建议后的更改:
@model SeaConnectionManager.Modelos.EnvioMensajes.InformacionEntity
@{ var previsualizaciones = "";
if (Model != null) {
previsualizaciones = Model.vistaPrevia;
}
}
<div id="Envio" class="overlay">
<div class="popup">
<h2 align="center">Información del Envío</h2>
<a class="close" href="#">×</a>
<div class="content" style="width:100%; margin:auto; padding:10px">
<center>
<a id="tabs">
<ul>
@if (Model != null) {
if (Model.cantidadMensajes >= 5)
{
for (var i = 1; i <= 5; i++)
{
<li><a href="#tabs-@i"> @i</a></li>
}
}
else {
for (var i = 1; i <= Model.cantidadMensajes; i++)
{
<li><a href="#tabs-@i"> @i</a></li>
}
}
}
</ul>
@previsualizaciones
</div>
<table width="100%" border="0" align="center" cellspacing="4">
<tr>
<td width="36%">Cantidad de mensajes</td>
<td width="44%">
@Html.TextBoxFor(m => m.cantidadMensajes, new { @id = "CantidadMensajes", @class = "input-login", @readonly = "readonly" })
</td>
</tr>
<tr>
<td>Cantidad de contactos</td>
<td>
@Html.TextBoxFor(m => m.cantidadContactos, new { @id = "CantidadContactos", @class = "input-login", @readonly = "readonly" })
</td>
</tr>
<tr>
<td>Saldo</td>
<td>
@Html.TextBoxFor(m => m.saldo, new { @id = "Saldo", @class = "input-login", @readonly = "readonly" })
@Html.HiddenFor(m => m.idTransaccion, new { @id = "idTransaccion" })
</td>
</tr>
</table>
</center><br>
<center>
<table width="122" border="0" align="center" cellspacing="10">
<tr>
<td width="51"><a onclick="EnviarMensajes()" class="boton-para-enviar" style="margin:auto">Aprobar</a></td>
<td width="37"><a href="#" class="boton-para-NO-enviar" style="margin:auto">Rechazar</a></td>
</tr>
</table>
</center>
<br>
<strong>Nota:</strong> Si el saldo no se encuentra completo para la cantidad total de mensajes, los mensajes que queden pendientes se enviarán cuando realice la recarga.
</div>
</div>
</div>
@model SeaConnectionManager.Modelos.enviromesajes.InformacionEntity
@{var previsualizaciones=”“;
如果(Model!=null){
previsualizaciones=Model.vistaPrevia;
}
}
环境信息
}
}
否则{
对于(var i=1;i m.cantidadMensajes,new{@id=“cantidadMensajes”、@class=“input login”、@readonly=“readonly”})
康蒂达德酒店
@TextBoxFor(m=>m.cantidadContactos,新的{@id=“cantidadContactos”,@class=“input login”,@readonly=“readonly”})
萨尔多
@TextBoxFor(m=>m.saldo,新的{@id=“saldo”,@class=“input login”,@readonly=“readonly”})
@HiddenFor(m=>m.idTransaccion,new{@id=“idTransaccion”})
注:这是一个不完整的项目,它是一个完整的项目,它是一个完整的项目。
检查控制器:
public ActionResult EnviarMensajeIndividual(MensajesEntity model)
{
InformacionEntity Info = new InformacionEntity();
Info.error = false;
model.usuarioCreacion = User.Identity.Name;
if (HttpContext.Session["Lista"] != null && model.mensaje != null)
{
List<ContactoEntity> lista = HttpContext.Session["Lista"] as List<ContactoEntity>;
int idTransaccion = mdm.EnviarMensajes(model, lista, 1);
if (idTransaccion > 0)
{
Info = mdm.InformacionDeEnvio(idTransaccion);
Info.error = false;
}
else
{
//error
Info.error = true;
Info.mensajeError = "error.";
}
}
else
{
// tiene q tener contactos agregados
Info.error = true;
Info.mensajeError = "error";
}
var js = new JavaScriptSerializer();
var Data = new ContentResult();
js.MaxJsonLength = Int32.MaxValue;
Data.Content = js.Serialize(Info);
Data.ContentType = "application/json";
return Data;
}
公共行动结果环境个体(男性实体模型)
{
InformacionEntity Info=新的InformacionEntity();
Info.error=false;
model.usuarioCreacion=User.Identity.Name;
if(HttpContext.Session[“Lista”!=null&&model.mensaje!=null)
{
将lista=HttpContext.Session[“lista”]列为列表;
int idTransaccion=mdm.EnviarMensajes(型号,列表A,1);
如果(IDTransacion>0)
{
Info=mdm.INFORCIONDEVIO(IDTRANCION);
Info.error=false;
}
其他的
{
//错误
Info.error=true;
Info.mensajerror=“错误。”;
}
}
其他的
{
//tiene q tener agregados联系人
Info.error=true;
Info.mensajerror=“错误”;
}
var js=新的JavaScriptSerializer();
var Data=new ContentResult();
js.MaxJsonLength=Int32.MaxValue;
Data.Content=js.Serialize(Info);
Data.ContentType=“应用程序/json”;
返回数据;
}
从模型中删除@
@if (Model != null) {
if (Model.cantidadMensajes >= 5)
{
for (var i = 1; i <= 5; i++)
{
<li><a href="#tabs-@i"> @i</a></li>
}
}
else {
for (var i = 1; i <= Model.cantidadMensajes; i++)
{
<li><a href="#tabs-@i"> i</a></li>
}
}
}
@if(Model!=null){
如果(Model.cantidadMensajes>=5)
{
对于(var i=1;i从模型中删除@)
@if (Model != null) {
if (Model.cantidadMensajes >= 5)
{
for (var i = 1; i <= 5; i++)
{
<li><a href="#tabs-@i"> @i</a></li>
}
}
else {
for (var i = 1; i <= Model.cantidadMensajes; i++)
{
<li><a href="#tabs-@i"> i</a></li>
}
}
}
@if(Model!=null){
如果(Model.cantidadMensajes>=5)
{
对于(var i=1;i模型被赋予null值的原因是,在视图的顶部,您有以下内容:
@model SeaConnectionManager.Modelos.enviromesajes.InformacionEntity代码>
因此,您的视图需要一个类型为InformacionEntity
的对象
但是,在控制器中,您应该将该对象返回到视图中,您没有返回InformacionEntity
对象
因此,在控制器中,您有:
InformacionEntity Info=newinformacionentity();