2

I am not 100% how to tackle this.

I have a basic controller who retrieves data from a table called transactions

CONTROLLER private NWBA_DBEntities db = new NWBA_DBEntities();

    public ActionResult Index()
    {
        var statements = db.Transactions.ToList();
        return View(statements);

    }

I have basic model:

public class StatementModel
{

    [StringLength(50)]
    [Display(Name="Transaction Type: ")]
    public string TransactionType { get; set; }

    [StringLength(50)]
    [Display(Name = "AccountNumber")]
    public string AccountNumber { get; set; }



}

My problem is at the View, i cant seem to display the values in a table:

@model Login.Models.StatementModel

@{
    ViewBag.Title = "Statements";
}


<h2>Index</h2>

<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.TransactionType)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.AccountNumber)
        </th>

        <th></th>
    </tr>

    @foreach (var item in Model) 
    {
    <tr>

    </tr>
}
</table>

Can some one please help

1
  • you are not saving the values in the Statement model in the Action method in the controller. Commented Sep 29, 2013 at 7:29

1 Answer 1

4
public ActionResult Index()
    {
        var statementModel = from s in db.Transactions
                            select new StatementModel
                            {
                                TransactionType  = s.TransactionType,
                                AccountNumber = s.AccountNumber
                            }
        return View(statementModel);

    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.