在MVC2中的视图页面中显示表行 [英] Displaying table row in view Page in MVC2

查看:82
本文介绍了在MVC2中的视图页面中显示表行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我在MVC2中遇到问题,无法在视图页面上显示数据库记录.我有这样的产品模型

Hello every one

I am facing a problem in MVC2 to diaplay the Data Base record on the view page . I am having a Product model like this

public class ProductDetails:IEnumerable
    {
        [Required (ErrorMessage="Product name required")]
        public string ProductName { get; set; }

        [Required(ErrorMessage = "Product Id cannot be blank")]
        [Range(0,50,ErrorMessage="Enter only digit")]
        public string ProductID { get; set; }

        [Required(ErrorMessage = "Product amount cannot be blank")]
        [Range(0, 10000, ErrorMessage = "Enter only digit")]
        public string amount { get; set; }

        [Required(ErrorMessage = "Product Manifacturing cannot be blank")]
        [Range(0, 9999, ErrorMessage = "Enter only digit")]
        public string Manifacturing { get; set; }

}



这里显示的是错误消息,例如不实现接口成员"

所以任何人都可以告诉我这段代码有什么问题.我是MVC的初学者,我掌握了MVC的全部知识.在实施中

我在从DB检索数据并在视图页面上对其进行diaplay时遇到问题....

甚至我在doung foreach中遇到问题



here it is showing a error message like "Does not implement interface member"

So can any body tell me what''s wrong in this code . I am a beginner to MVC I got over all articture of MVC . In Implementing

I am facing problem in retriving data from DB and diaplay it on view page....

Even I am getting problem in doung foreach

<table>
   <tr><td></td><td></td><td></td><td></td></tr>
   <tr><td>Product ID</td><td>Product Name</td><td>Amount</td><td>Manifacturing</td></tr>

 <%foreach (var item in Model)
   {

   } %>
   </table>



它显示错误为模型与声明冲突"我没有得到这个,我正在使用Linque和存储过程来

获取数据.数据正在从数据库中获取.我的问题是我无法在查看屏幕上显示数据

(通过控制器显示零件)

所以任何机构都可以帮助我获取数据显示(我在MVC2中没有剃须刀)



It is showing error as "Model conflicts with the declaration" I am not getting this I am Using Linque and store procedure to

fetch data . The data is getting fetch from data base . My problem is I am not able to display data on the view screen

(display part through controller)

So can any body help me to get data Display (I am not having razor in MVC2)

推荐答案

在显示项目列表的屏幕上必须添加@model IEnumerable t其中T是要绑定视图的类型.

您可以在ProductDetails类中消除IEnumerable

最简单的方法是


将属性添加到绑定模型类,例如List< productdetails>产品列表
在视图@model< namespace> .yourModel
中声明模型
填写ProductList并使用像这样的控制器加载它

at the screen displaying the items list in you have to add @model IEnumerable<t> where T is the type to which you want bind your view.

You can eliminate the IEnumerable in your ProductDetails class

Simplest way to do this is


Add a property to binding Model Class like List<productdetails> ProductList
Declare the model in view @model <namespace>.yourModel

Fill the ProductList and load it using controller like this

Public ActionResult ControllerAction()
{
MyModel = new MyModel(){
ProductList = GetProductslistFromDB();
};
return View("YouViewwName",MyModel );
}



在视图中使用此代码



At the View Use this code

<%foreach (var item in Model.ProductList)
  {
<%item.Name%/> etc etc
  } %>



抱歉,因为我更了解剃刀,所以无法完成HTML中的代码.



Sorry I could not complete the code in HTML as I know razor better.


这篇关于在MVC2中的视图页面中显示表行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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