ASP.NET MVC中包含数据库的多个选项卡 [英] Multiple tabs with database in ASP.NET MVC

查看:66
本文介绍了ASP.NET MVC中包含数据库的多个选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个标签。我正在使用asp.net mvc。使用一个选项卡我能够插入数据。但是当我从backebd插入空行的第一个标签的另一个标签表插入数据时



这是我的观点



i have 2 tabs. i am using asp.net mvc. with one tab i am able to insert data.but when i insert data from another tab table of first tab in backebd inserting null row

this is my view

@model MathuraApp.Models.CurrencyCreationModel
   


@{
   ViewBag.Title = "currency";
    Layout = "~/Views/Shared/_AccountLayout.cshtml";
}

<h2>currency</h2>

@*@using (Html.BeginForm())


    {*@
@Html.AntiForgeryToken()
      BEGIN INLINE TABS PORTLET
<div class="widget">
    <div class="widget-title">
        <h4><i class="icon-user"></i></h4>
    </div>
    <div class="widget-body">
        <div class="row-fluid">
            <div class="span8">
            </div>
        </div>
    </div>
</div>

<div class="tabbable custom-tab">
    <h4>CurrencyCreationModel</h4>
    <hr />
    <ul class="nav nav-tabs">
        <li class="active"><a href="#tab_1_1" data-toggle="tab">Currency Creation</a></li>
        <li><a href="#tab_1_2" data-toggle="tab">Currency Converter</a></li>

    </ul>
    <div class="tab-content">


        <div class="tab-pane  " id="tab_1_2">
            @using (Html.BeginForm("Currency", "CurrencyCreation",FormMethod.Post,new { }))
            {

                @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                <div class="form-group">
                    @Html.LabelFor(model =&gt; model.SecondaryCurrency, htmlAttributes: new { @class = "control-label col-md-2" })
                    <div class="col-md-10">
                        @Html.EditorFor(model =&gt; model.SecondaryCurrency, new { htmlAttributes = new { @class = "form-control" } })
                        @Html.ValidationMessageFor(model =&gt; model.SecondaryCurrency, "", new { @class = "text-danger" })
                    </div>
                </div>

                <div class="form-group">
                    @Html.LabelFor(model =&gt; model.ConvRate, htmlAttributes: new { @class = "control-label col-md-2" })
                    <div class="col-md-10">
                        @Html.EditorFor(model =&gt; model.ConvRate, new { htmlAttributes = new { @class = "form-control" } })
                        @Html.ValidationMessageFor(model =&gt; model.ConvRate, "", new { @class = "text-danger" })
                    </div>
                </div>

                <div class="form-group">
                    @Html.LabelFor(model =&gt; model.PrimaryCurrency, htmlAttributes: new { @class = "control-label col-md-2" })
                    <div class="col-md-10">
                        @Html.EditorFor(model =&gt; model.PrimaryCurrency, new { htmlAttributes = new { @class = "form-control" } })
                        @Html.ValidationMessageFor(model =&gt; model.PrimaryCurrency, "", new { @class = "text-danger" })
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        &lt;input type="submit" value="submit" class="btn btn-default" /&gt;
                    </div>
                </div>


                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10" style="color:green">
                        @ViewBag.Message

                    </div>
                </div>


            }

        </div>


        <div class="tab-pane active " id="tab_1_1">

            @using (Html.BeginForm("currency", "CurrencyCreation", FormMethod.Post, new { }))
            {
                @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                <div class="form-group">
                    @Html.LabelFor(model =&gt; model.Currency_Name, htmlAttributes: new { @class = "control-label col-md-2" })
                    <div class="col-md-10">
                        @Html.EditorFor(model =&gt; model.Currency_Name, new { htmlAttributes = new { @class = "form-control" } })
                        @Html.ValidationMessageFor(model =&gt; model.Currency_Name, "", new { @class = "text-danger" })
                    </div>
                </div>

                <div class="form-group">
                    @Html.LabelFor(model =&gt; model.CurrencySymbol, htmlAttributes: new { @class = "control-label col-md-2" })
                    <div class="col-md-10">
                        @Html.EditorFor(model =&gt; model.CurrencySymbol, new { htmlAttributes = new { @class = "form-control" } })
                        @Html.ValidationMessageFor(model =&gt; model.CurrencySymbol, "", new { @class = "text-danger" })
                    </div>
                </div>

                    <div class="form-group">
                        @Html.LabelFor(model =&gt; model.Abbreviation, htmlAttributes: new { @class = "control-label col-md-2" })
                        <div class="col-md-10">
                            @Html.EditorFor(model =&gt; model.Abbreviation, new { htmlAttributes = new { @class = "form-control" } })
                            @Html.ValidationMessageFor(model =&gt; model.Abbreviation, "", new { @class = "text-danger" })
                        </div>
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model =&gt; model.Sub_Currency, htmlAttributes: new { @class = "control-label col-md-2" })
                        <div class="col-md-10">
                            @Html.EditorFor(model =&gt; model.Sub_Currency, new { htmlAttributes = new { @class = "form-control" } })
                            @Html.ValidationMessageFor(model =&gt; model.Sub_Currency, "", new { @class = "text-danger" })
                        </div>
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model =&gt; model.Decimal_Place, htmlAttributes: new { @class = "control-label col-md-2" })
                        <div class="col-md-10">
                            @Html.EditorFor(model =&gt; model.Decimal_Place, new { htmlAttributes = new { @class = "form-control" } })
                            @Html.ValidationMessageFor(model =&gt; model.Decimal_Place, "", new { @class = "text-danger" })
                        </div>
                    </div>

                    <div class="form-group">
                        @Html.LabelFor(model =&gt; model.Comments, htmlAttributes: new { @class = "control-label col-md-2" })
                        <div class="col-md-10">
                            @Html.EditorFor(model =&gt; model.Comments, new { htmlAttributes = new { @class = "form-control" } })
                            @Html.ValidationMessageFor(model =&gt; model.Comments, "", new { @class = "text-danger" })
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-md-offset-2 col-md-10">
                            &lt;input type="submit" value="submit" class="btn btn-default" /&gt;
                        </div>
                    </div>



                    <div class="form-group">
                        <div class="col-md-offset-2 col-md-10" style="color:green">
                            @ViewBag.Message

                        </div>
                    </div>


            }
        </div>







这是我的控制器








this is my controller


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MathuraApp.Repository;
using MathuraApp.Models;

namespace MathuraApp.Controllers
{
    public class CurrencyCreationController : Controller
    {
        // GET: CurrencyCreation

     
        public ActionResult currency()
        {
            return PartialView();
        }
      


        [HttpPost]
        public ActionResult currency(CurrencyCreationModel ccm)
        {
           try
           {
                if (ModelState.IsValid)
               {
                    CurrencyCreationRepository ccr = new CurrencyCreationRepository();
                  
                    if (ccr.Currency(ccm) )
                    {
                        ViewBag.Message = "Currency details added successfully";
                        
                    }
                    CurrencyConverterRepository ccr1 = new CurrencyConverterRepository();

               if (ccr1.Currency(ccm))
                    {
                        ViewBag.Message = "Currencyconverter details added successfully";
                    }
                }

                return PartialView(ccm);
            }
            catch
            {
                return PartialView(ccm);
            }

           

      
           


        }


        //public ActionResult Converter(CurrencyCreationModel ccm)
        //{
        //    try
        //    {
        //        if (ModelState.IsValid)
        //        {
        //            CurrencyCreationRepository ccro = new CurrencyCreationRepository();

        //            if (ccro.Converter(ccm))
        //            {
        //                ViewBag.Message = "Currency details added successfully";
        //            }
        //        }

        //        return View(ccm);
        //    }
        //    catch
        //    {
        //        return View(ccm);
        //    }
        //}


    }
}

推荐答案

I can’t read that pile of code you posted because it’s not formatted and enclosed in PRE tags.



But, in the web world, your tabs are VISUALLY separate, not separate from each other as far as a form tag or the code is concerned. What it appears that you’re doing is you have two forms, one nested inside the other. When you submit the form that you think is one one form, you’re actually submitting both of them.



Your controller code also doesn’t appear to check to see if the data that it’s getting is valid. Sure, you check ModelState.IsValid, but that only goes so far to make sure certain fields are filled in. It has no way of knowing if the data in those fields is valid per your business logic.
I can't read that pile of code you posted because it's not formatted and enclosed in PRE tags.

But, in the web world, your tabs are VISUALLY separate, not separate from each other as far as a form tag or the code is concerned. What it appears that you're doing is you have two forms, one nested inside the other. When you submit the form that you think is one one form, you're actually submitting both of them.

Your controller code also doesn't appear to check to see if the data that it's getting is valid. Sure, you check ModelState.IsValid, but that only goes so far to make sure certain fields are filled in. It has no way of knowing if the data in those fields is valid per your business logic.


这篇关于ASP.NET MVC中包含数据库的多个选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆