1

I am creating finance application in mvc 4 and razor. in that there is one module Journal. One Journal can have multiple entries. and Journal can not be created without Journal Entry.

Following is my model

using Sms.Core;
using System;
using System.Collections.Generic;
namespace Sms.CoreSociety
{
    public class Journal : BaseClass
    {
        public Journal()
        {
            this.JournalEntries = new List<JournalEntry>();
        }
        public virtual string VoucherNo { get; set; }
        public virtual DateTime VoucherDate { get; set; }
        public string VoucherDateView
        {
            get
            {
                return VoucherDate.ToShortDateString();
            }
        }
        public IList<JournalEntry> JournalEntries { get; set; }
        public IList<Ledger> Accounts { get; set; }
        public double TotalAmount
        {
            get
            {
                double sum = 0;
                if (JournalEntries != null && JournalEntries.Count > 0)
                    foreach (var journal in JournalEntries)
                        sum = journal.Principal + journal.Interest + sum;
                return sum;
            }
        }
    }
}

Following is my View

@model Sms.CoreSociety.Journal
@{
    ViewBag.Title = "Create";
}

@using (Html.BeginForm(null, null, FormMethod.Post, new Dictionary<string, object>() { { "class", "form-horizontal" }, { "id", "document" } }))
{
    @Html.ValidationSummary(true)

    <fieldset>
        <div class="row">
            <div class="span1">
                <label>
                    Voucher No</label>
            </div>
            <div class="span5">
                @Html.TextBoxFor(model => model.VoucherNo)
            </div>
        </div>
        <div class="row">
            <div class="span1">
                <label>
                    Voucher Date</label>
            </div>
            <div class="span5">
                @Html.TextBoxFor(model => model.VoucherDate)
            </div>
        </div>
        <div class="row">
            <div class="span1">
                <label>
                    Amount</label>
            </div>
            <div class="span5">
                @Html.TextBoxFor(model => model.TotalAmount)
            </div>
        </div>
        @Html.TextBox("JournalEntries[0].AccountName", Model.JournalEntries.FirstOrDefault().AccountName)
        @Html.TextBox("JournalEntries[0].DebitCredit", Model.JournalEntries.FirstOrDefault().DebitCredit)
        @Html.TextBox("JournalEntries[0].Interest", Model.JournalEntries.FirstOrDefault().Interest)
        @Html.TextBox("JournalEntries[0].Narration", Model.JournalEntries.FirstOrDefault().Narration)

        <input type="submit" value="Save" class="btn" id="submit" />
        @if (Model.Id != new Guid())
        {
            <div style="float: right">
                <a class="btn btn-danger" href='@Url.Action("Delete")/@Model.Id' aria-hidden="true">
                    Delete</a>
            </div>
        }
    </fieldset>
}
<h4>
    Journal Entry</h4>
<p>
@Html.ActionLink("Add Entry", "JournalEntry");

Now I am able to get the Journal as well as Single Journal Entry. But my problem is I am not able to make Multiple journal entry.

This is what i am looking for but in MVC 4 and razor without knockout.js

2
  • I'm confused. Do you want to use knockout or not? That article does not include knockout.js. Commented Sep 14, 2013 at 19:59
  • i don't want to use knockout.js, i have got one exmple using knockout.js i tried that but when i deploy that code the server doesn't starts.. Commented Sep 14, 2013 at 21:04

1 Answer 1

2

To achieve your goal, you need to do some extra works by jquery, ajax and partial views.

A brief example is here. A full howto is here.

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.