Click here to Skip to main content
15,889,361 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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; }

}


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
C#
<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>


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)
Posted

1 solution

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

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


At the View Use this code
HTML
<%foreach (var item in Model.ProductList)
  {
<%item.Name%/> etc etc
  } %>


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900