locked
how to add record tow table same time from one View RRS feed

  • Question

  • User-2035378889 posted

    Dear's fellows due to a new in asp.net mvc  am have problem with adding record in tow table at a time form one view

    this is my supplier model

    using PharmaApp.Core.DataModel.Base;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace PharmaApp.Core.DataModel
    {
        [Table("Supplier")]
        public class SupplierModel : BaseModel
        {
            [Required]
            public string  Name { get; set; }        
            public string Email { get; set; }
            public string TrialCategory { get; set; }
            public string AccountType { get; set; }
            public string AccountSubType { get; set; }
            public string PartyType { get; set; }
            public string ItemType { get; set; }
            public string Drcr { get; set; }
            public new string Company { get; set; }
            public int Bf { get; set; }
            public DateTime BFDate { get; set; }       
            public string Phone { get; set; }
            public string Address { get; set; }
            public string Notes { get; set; }
           

        }
    }

    This is my 2 model 

    using PharmaApp.Core.DataModel.Base;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace PharmaApp.Core.DataModel
    {
        [Table("Ledger")]
        public class LedgersModel : BaseModel
        {


            [DisplayName("AccountsName")]
            [ForeignKey("SupplierModel")]
            public Nullable<int> AcId { get; set; }
            public SupplierModel SupplierModel { get; set; }
            public Nullable<int> EntryId { get; set; }
            public Nullable<DateTime> EntryDate { get; set; }
            public Nullable<int> BillNo { get; set; }
            public string Deacripation { get; set; }
            public Nullable<int> DrAmount { get; set; }
            public Nullable<int> CrAmount { get; set; }
          
            public string Sp { get; set; }

            public string UserName { get; set; }
        }
    }

    And This is my View

    @model PharmaApp.Core.DataModel.SupplierModel
    @{
        ViewBag.Title = "Add New Account";
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker3.css" rel="stylesheet" />
    <div class="wraper container-fluid">
        <div class="page-title">
            <h3 class="title">Chart Of Account </h3>
        </div>
        <div class="row">
            <div class="col-lg-10 col-md-offset-1">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">New Account</h3>
                    </div>
                    <div class="panel-body">
                        @using (Html.BeginForm("AddSupplier", "Admin", FormMethod.Post))
                        {
                            @Html.AntiForgeryToken()
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="AccountType"> Account Name: </label>
                                    @Html.TextBoxFor(x => x.Name, null, new { @class = "form-control", @placeholder = "Enter Name " })
                                    @Html.ValidationMessageFor(x => x.Name, "", new { @class = "text-danger" })
                                </div>
                            </div>

                            <div class="form-group col-md-4">
                                <label for="AccountType"> Account Type: </label>
                                @Html.DropDownList("AccountType", new List<SelectListItem>
                                    {
                                        new SelectListItem() {Text = "Assets", Value="Assets"},
                                        new SelectListItem() {Text = "Liabilities", Value="Liabilities"},
                                    },  new { @class = "form-control", onchange = "blankme(this.id)" })

                                @Html.ValidationMessageFor(x => x.AccountType, "", new { @class = "text-danger" })
                            </div>
                            <div class="form-group col-md-4">
                                <label for="AccountSubType"> Account Sub Type: </label>
                                   @Html.DropDownList("AccountSubType", new List<SelectListItem>
                                    {
                                        new SelectListItem() {Text = "Current Assets", Value="Current Assets"},
                                        new SelectListItem() {Text = "Accounts Receivable", Value="Accounts Receivable"},
                                         new SelectListItem() {Text = "Other Current Assets", Value="Other Current Assets"},
                                          new SelectListItem() {Text = "Inventory", Value="Inventory"},
                                           new SelectListItem() {Text = "Cash", Value="Cash"},
                                            new SelectListItem() {Text = "Fixed Assets", Value="Fixed Assets"},
                                             new SelectListItem() {Text = "Current Liabilities", Value="Current Liabilities"},
                                              new SelectListItem() {Text = "Accounts Payable", Value="Accounts Payable"},
                                                new SelectListItem() {Text = "Other Current Liabilities", Value="Other Current Liabilities"},
                                                new SelectListItem() {Text = " Payroll Liabilities", Value=" Payroll Liabilities"},
                                                new SelectListItem() {Text = "Long Term Liabilities", Value="Long Term Liabilities"},
                                                new SelectListItem() {Text = "Equity", Value="Equity"}
                                    },  new { @class = "form-control", onchange = "blankme(this.id)" })

                                @Html.ValidationMessageFor(x => x.AccountType, "", new { @class = "text-danger" })
                            </div>
                            <div class="form-group col-md-4">
                                <label for="AccountType"> Category: </label>
                                @Html.DropDownList("TrialCategory", new List<SelectListItem>
                                    {
                                        new SelectListItem() {Text = "Party", Value="Party"},
                                        new SelectListItem() {Text = "Bank", Value="Bank"},
                                         new SelectListItem() {Text = "Item", Value="Item"},
                                          new SelectListItem() {Text = "Cash", Value="Cash"},
                                          new SelectListItem() {Text = "Assets", Value="Assets"},
                                           new SelectListItem() {Text = "Expenses", Value="Expenses"},
                                           new SelectListItem() {Text = "Income", Value="Income"},
                                    },  new { @class = "form-control", onchange = "blankme(this.id)" })

                                @Html.ValidationMessageFor(x => x.AccountType, "", new { @class = "text-danger" })
                            </div>
                            <div class="form-group col-md-4">
                                <div class="form-group">
                                    <label for="Date">Party Type  : </label>
                                    @Html.TextBoxFor(x => x.PartyType, null, new { @class = "form-control", @placeholder = "Part Type " })
                                    @Html.ValidationMessageFor(x => x.PartyType, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group col-md-4">
                                <div class="form-group">
                                    @Html.LabelFor(x => x.ItemType)
                                    @Html.TextBoxFor(x => x.ItemType, null, new { @class = "form-control", @placeholder = "Item Type " })
                                    @Html.ValidationMessageFor(x => x.ItemType, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="form-group col-md-4">
                                    @Html.LabelFor(x => x.Phone)
                                    @Html.TextBoxFor(x => x.Phone, null, new { @class = "form-control", @placeholder = "Enter Phone Number " })
                                    @Html.ValidationMessageFor(x => x.Phone, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group col-md-4">
                                <div class="form-group">
                                    @Html.LabelFor(x => x.Email)
                                    @Html.TextBoxFor(x => x.Email, null, new { @class = "form-control", @placeholder = "Enter Email " })
                                    @Html.ValidationMessageFor(x => x.Email, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group col-md-4">
                                <div class="form-group">
                                    @Html.LabelFor(x => x.Address)
                                    @Html.TextAreaFor(x => x.Address, new { @class = "form-control", @rows = "3", @placeholder = "Address" })
                                    @Html.ValidationMessageFor(x => x.Address, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="Date">BF Date  : </label>
                                    @Html.TextBox("Bfdate", null, new { @class = "form-control mydatepicker", @placeholder = "Select BF Date ", onchange = "blankme(this.id)" })
                                    @Html.ValidationMessageFor(x => x.BFDate, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group col-md-4">
                                <div class="form-group">
                                    @Html.LabelFor(x => x.Bf)
                                    @Html.TextBoxFor(x => x.Bf, null, new { @class = "form-control", @placeholder = "Amount " })
                                    @Html.ValidationMessageFor(x => x.Bf, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group col-md-4">
                                <label for="Drcr"> Dr/Cr: </label>
                                @Html.DropDownList("Drcr", new List<SelectListItem>
                                    {
                                        new SelectListItem() {Text = "Dr", Value="Dr"},
                                        new SelectListItem() {Text = "Cr", Value="Cr"},
                                    },  new { @class = "form-control", onchange = "blankme(this.id)" })

                                <small id="error_Payment" class="form-text error_msg">Select Dr/Cr</small>
                            </div>

                            <button type="submit" class="btn btn-purple">
                                Submit
                            </button>
                        }
                    </div>
                </div>
            </div>

        </div>
    </div>
    @section scripts {
        <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/js/bootstrap-datepicker.js"></script>

        @Scripts.Render("~/bundles/App")
    }

    I wnat to add ID,Bfdate from supplier to ledger

    in  AcId,EntryDate

    please help me

    Wednesday, April 14, 2021 6:35 PM

All replies

  • User475983607 posted

    The common issue we see on the forums is the View input names do not match the action model parameter names.  You did not supply the View or base model. 

    You are using a custom repository and did not supply the repository code. 

    Typically, the exception message tells you the exact line of code that caused the exception as well as the item that is null which you did not supply either.  

    I recommend learning how to use the Visual Studio debugger to to figure where the problem starts then fixing the problem.  If you want community debugging support then you must supply enough code for the community to reproduce the issue.  

    Wednesday, April 14, 2021 7:17 PM