如何在mvc3中查看模态 [英] How to view modal in mvc3

查看:59
本文介绍了如何在mvc3中查看模态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我在mvc中开发了视图模式:我有一个错误



CS1061:'Telecom.ViewModel.VwModel'不包含'MRSHdr'的定义,并且没有可以找到接受类型'Telecom.ViewModel.VwModel'的第一个参数的扩展方法'MRSHdr'(您是否缺少using指令或汇编参考?)



第21行:@ Html.TextBoxFor(model => model.MRSHdr.MRNo)

第22行: @ Html.TextBoxFor(model => model.MRSHdr.MRDate)



我尝试过:



模态:

[表(MRHdr)]

公共类MRHdr

{

[Key]

[Column(Order = 0)]

public int Id {get;组; }

public string MRNo {get;组; }

public DateTime MRDate {get;组; }

public string备注{get;组; }

公共字符串GetUser {get;组; }

public string DelFlag {get;组; }

公共日期时间? GetDate {get;组; } $ / $
public string CompCode {get;组; }



}



[表(MRDtl)]

公共类MRDtl

{

[Key]

[Column(Order = 0)]

public int Id {get;组; }

public string MRNo {get;组; }

[必需(AllowEmptyStrings = false,ErrorMessage =需要项目名称!)]

public string IRateCode {get;组; }

公共字符串ItemCode {get;组; }

[必需(AllowEmptyStrings = false,ErrorMessage =需要数量!)]

public int QtyRequested {get;组; }

}



ViewModel:

公共类VwModel

{

public MRHdr MRHdr {get;组; }

public MRDtl MRDtl {get;组; }

}



控制器:

public ActionResult Create()

{

返回查看();

}



PartialView:

@model IEnumerable的<电信。视图模型。 vwmodel>

@ {



}

< style>

th {

text-align:left;

}

td {

填充:5px;

}

< / style>



Dear Friends,

I have developed view modal in mvc: I have got an error

CS1061: 'Telecom.ViewModel.VwModel' does not contain a definition for 'MRSHdr' and no extension method 'MRSHdr' accepting a first argument of type 'Telecom.ViewModel.VwModel' could be found (are you missing a using directive or an assembly reference?)

Line 21: @Html.TextBoxFor(model => model.MRSHdr.MRNo)
Line 22: @Html.TextBoxFor(model => model.MRSHdr.MRDate)

What I have tried:

Modal:
[Table("MRHdr")]
public class MRHdr
{
[Key]
[Column(Order = 0)]
public int Id { get; set; }
public string MRNo { get; set; }
public DateTime MRDate { get; set; }
public string Remarks { get; set; }
public string GetUser { get; set; }
public string DelFlag { get; set; }
public DateTime? GetDate { get; set; }
public string CompCode { get; set; }

}

[Table("MRDtl")]
public class MRDtl
{
[Key]
[Column(Order = 0)]
public int Id { get; set; }
public string MRNo { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage = "Item Name required!")]
public string IRateCode { get; set; }
public string ItemCode { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage = "Quantity required!")]
public int QtyRequested { get; set; }
}

ViewModel:
public class VwModel
{
public MRHdr MRHdr { get; set; }
public MRDtl MRDtl { get; set; }
}

Controller:
public ActionResult Create()
{
return View();
}

PartialView:
@model IEnumerable< telecom. viewmodel. vwmodel>
@{

}
<style>
th {
text-align:left;
}
td {
padding:5px;
}
</style>



@using(Html.BeginForm (创建,MatReq,FormMethod.Post))

{


@using (Html.BeginForm("Create","MatReq", FormMethod.Post))
{





@if(型号!= null&& Model.Count> 0)

{

int j = 0;

foreach(模型中的var i)

{

j ++;

}

}

< tr>
项目名称 项目费率代码 项目代码 数量要求
@ Html.TextBox(ItemName,null,new {id =ItemName}) @ Html.TextBoxFor(a => a [j] .IRateCode) @ Html.TextBoxFor(a => a [j] .ItemCode) @ Html.TextBoxFor(a => a [j] .QtyRequested) @if(j> 0)

{

删除

}



< input type =submitvalue =Save/> ;;



}



@if (Model != null && Model.Count > 0)
{
int j = 0;
foreach (var i in Model)
{
j++;
}
}

Item Name Item Rate Code Item Code Qty Requested
@Html.TextBox("ItemName", null, new { id = "ItemName" }) @Html.TextBoxFor(a=>a[j].IRateCode) @Html.TextBoxFor(a=>a[j].ItemCode) @Html.TextBoxFor(a=>a[j].QtyRequested) @if (j > 0)
{
Remove
}

<input type="submit" value="Save" />;

}

推荐答案

您的模型定义了MRHdr



Your model defines MRHdr

public MRHdr MRHdr { get; set; }





但您的代码使用MRSHdr





but your code uses MRSHdr

@Html.TextBoxFor(model => model.MRSHdr.MRNo)





更改TextBoxFor以使用MRHdr,或更改属性在模型中是MRSHdr,但两者必须匹配。



Change the TextBoxFor to use MRHdr, or change the property in the model to be MRSHdr, but the two have to match.


这篇关于如何在mvc3中查看模态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆