Click here to Skip to main content
16,019,018 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm using three different viewmodels - *Header, *Details and *Conditions respectively.
I've saved the data in three tables using MVC and Entity Framework (database first).

*before name of view models can be Quotation, Purchase Order, Invoice etc... like QuotationHeader,InvoiceHeader.....

*Details and *Conditions are common among Quotation, Purchase Order, Invoice etc...

So I've used partial views for *details and *conditions. In my main view I'm calling

this two partial views. Now I've to edit that data the same way I've added it, partial view data should also get displayed and should be editable.

How can I implement such functionality in MVC ? Can any one please provide the solution ?

Given below is my code.

ViewModels:

* Quotation Viewmodel:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using iBillingMVC_Dev.ViewModel.Transactions;
using ibillingDB.Db;
using System.ComponentModel.DataAnnotations;

namespace iBillingMVC_Dev.ViewModel.Transactions
{
    public class QuotationHeaderViewModel
    {
        public string QuotationNO { get; set; }
        public int CompanyID { get; set; }
        public int FinYearID { get; set; }

        [Required(ErrorMessage = "Select Location")]
        [Display(Name = "Location")]
        public int LocationID { get; set; }
        public IEnumerable<SelectListItem> Locations { get; set; }

        [Required(ErrorMessage = "Select Customer")]
        [Display(Name = "Customer")]
        public int CustomerID { get; set; }
        public IEnumerable<SelectListItem> Customers { get; set; }

        [Required(ErrorMessage = "Enter Quotation Date")]
        [Display(Name = "Quotation Date")]
        public DateTime QuotDate { get; set; }

        public string Remark { get; set; }
        public int CreatedBy { get; set; }
        public DateTime CreatedOn { get; set; }
        public bool IsActive { get; set; }

        // Item Details //
        [Required(ErrorMessage = "Select Item")]
        [Display(Name = "Item")]
        public int ItemID { get; set; }
        public IEnumerable<SelectListItem> Items { get; set; }
        // End //

    }
}

Item details viewmodel:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using iBillingMVC_Dev.ViewModel.Transactions;
using ibillingDB.Db;
using System.ComponentModel.DataAnnotations;

namespace iBillingMVC_Dev.ViewModel.Transactions
{
    public class ItemDetailsViewModel
    {
        public int SortID { get; set; }
        [Required(ErrorMessage = "Select Item")]
        [Display(Name = "Item")]
        public int ItemID { get; set; }
        public IEnumerable<SelectListItem> Items { get; set; }
        public List<ItemDetailsTable> ItemList { get; set; }

    }
    public class ItemDetailsTable
    {
        public int ItemID { get; set; }
        public int Qty { get; set; }
        public decimal Rate { get; set; }
        public decimal TotalAmount { get; set; }
    }
}

Terms Conditions viewmodel:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using iBillingMVC_Dev.ViewModel.Transactions;
using ibillingDB.Db;
using System.ComponentModel.DataAnnotations;

namespace iBillingMVC_Dev.ViewModel.Transactions
{
    public class TermsConditionsViewModel
    {
        public List<TermsConditionTable> ConditionList { get; set; }
    }
    public class TermsConditionTable
    {
        public bool ischecked { get; set; }
        public int ConditionID { get; set; }
        public string ConditionName { get; set; }
    }

}
Posted
Updated 11-Sep-14 2:21am
v2
Comments
Nathan Minier 9-Sep-14 12:46pm    
It's all contingent on how you developed the models that are mapped to your database, which I'm assuming are different, as you're talking about ViewModels(which are not mapped directly to the database by definition).

If you want to save the partial views independently you can do that via AJAX. If you want to write a JavaScript that will collect the form data from 3 separate forms and send it, you can do that. If you want to include those partial views (with, say, inputs but no form tag) into the overall form and send it up as one big object, you can do that.

All that said, I'm shooting in the dark as far as what you're asking.

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