مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

rahimi.med

عضویت از 1396/08/03

ارسال داده از یک کنترلر به کنترلر دیگر

  • دوشنبه 6 آذر 1396
  • 19:40
تشکر میکنم

با سلام

من یک پروژه دارم که با ورود یک مقدار در تکست باکس به دیتابیس مراجعه می کند و در صورتی که مقدار ورودی بیشتر از یک مقدار مشخصی باشد به کاربر هشدار می دهد( به وسیله یک پنجره مدال)

چک کردن مقدار ورودی در یک کنترلر دیگری به جز کنترلر Home انجام می شود مثلا یک کنترلر به نام CheckData

حال سوال من اینجاست که چگونه می توان مقداری را  که در کنترلر CheckData با مقدار اولیه تکست باکس مقایسه کرده ام  در پنجره هشدار مدال که عملا در ویو Index در کنترلر Home نوشته شده نمایش دهم؟

با تشکر از دوستان

پاسخ های این پرسش

تعداد پاسخ ها : 5 پاسخ
کاربر سایت

سهیل علیزاده

عضویت از 1396/04/09

  • دوشنبه 6 آذر 1396
  • 19:49

لطفا سوال خود را به همراه کدهایتان توضیح دهید و آن ها را برای بررسی قرار بدید.

کاربر سایت

rahimi.med

عضویت از 1396/08/03

  • دوشنبه 6 آذر 1396
  • 23:45

view این کار

@{
    ViewBag.Title = "Home Page";
}


<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script>
    $(function(){
        $('#TxtName').on('change', function () {
            var n = $('#TxtName').val();

     $.ajax({
         type: 'POST',
            url:' @Url.Action("Home", "CheckData")',
            data: { First: $('#TxtName').val(), Second: $('#TxtRow').val()},
            datatype:JSON,

            success: function (response) {

                if (response == 'true') {

                    $('#P_Window').modal('show');

                }
                else {
                    $("#TxtSecond").focus();
                }
      }
    });
   });
    });
    function NoAnswer()
    {
        $('#P_Window').modal('hide');
        $('#P_NoAnswer').modal('show');
    }
</script>
<div class="jumbotron">
    <h1>سیستم مقایسه اعداد</h1>

</div>

<div class="row">
    @using (Html.BeginForm("Index", "ma", FormMethod.Get))
    {

        @Html.AntiForgeryToken()
        <div class="col-md-4">
            <h2>مشخص کننده شماره سطر </h2>
            <p>
                @Html.TextBox("TxtRow")
            </p>

        </div>
        <div class="col-md-4">
            <h2>مقدار فیلد دوم</h2>
            @Html.TextBox("TxtSecond")
        </div>
        <div class="col-md-4">
            <h2>مقدار فیلد اول</h2>
            @Html.TextBox("TxtName")
        </div>
    }
</div>
<div aria-hidden="true" class="modal fade" role="dialog" style="display: none;" tabindex="-1" id="P_Window">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" class="close" data-dismiss="modal" type="button">
                    ×
                </button>
                <h4 class="modal-title">پیام سیستم</h4>
            </div>
            <div class="modal-body" style="height:180px !important">
                <div class="widget-body form">
                    <div class="form-horizontal">
                        <table style="width: 100%; line-height: 35px;direction:rtl;text-align:right">
                            <tr>
                                <td>
                                    <div class="control-group">
                                        <div class="controls">
                                            مقدار وارد شده بیشتر از مقدار مجاز است ، آیا این مقدار را تغییر می دهید ؟
                                            <br />
                                        </div>
                                    </div>
                                </td>

                            </tr>


                        </table>
                        <br /><br />


                        <div class="control-group" style="float: right; width: 50%;">
                            <div class="form-actions">
                                @using (Html.BeginForm("YesAnswer", "Home", FormMethod.Get))
                                {

                                    <p style="direction:ltr;text-align:left">

                                        <input type="submit" style="width:100px;height:30px;text-align:center" class="btn-beoro-1" value="بله" />
                                    </p>
                                }


                            </div>
                        </div>
                        <div class="control-group" style="float: left; width: 50%;">
                            <div class="form-actions">



                                <p style="direction:rtl;text-align:right">

                                    <input type="submit" style="width:100px;height:30px;text-align:center" onclick="NoAnswer(); return false" class="btn-beoro-1" value="خیر" />
                                </p>


                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div aria-hidden="true" class="modal fade" role="dialog" style="display: none;" tabindex="-1" id="P_NoAnswer">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" class="close" data-dismiss="modal" type="button">
                    ×
                </button>
                <h4 class="modal-title">پیام سیستم</h4>
            </div>
            <div class="modal-body" style="height:300px !important">
                <div class="widget-body form">
                    @using (Html.BeginForm("RegisterAnswer", "Home", FormMethod.Get))
                    {
                        <div class="form-horizontal">
                            <table style="width: 100%; line-height: 35px;direction:rtl;text-align:right">
                                <tr>
                                    <td>
                                        <div class="control-group">
                                            <div class="controls">
                                                لطفا دلیل رد هشدار را ثبت نمایید
                                                <br />
                                            </div>
                                        </div>
                                    </td>

                                </tr>


                            </table>
                            <br /><br />


                            <div class="control-group" style="float: right; width: 100%;">
                                <div class="form-actions">
                                    <table style="width:100%;direction:rtl;text-align:right">
                                        <tr>
                                            <td>@Html.CheckBox("isCh1", false)1- مقدار غیر منطقی بود</td>

                                        </tr>
                                        <tr>
                                            <td>@Html.CheckBox("isCh2", false)2- مقدار قابل قبول نبود</td>
                                        </tr>
                                        <tr>
                                            <td>@Html.CheckBox("isCh3", false)3- مقدار مجاز نبود</td>
                                            <td style="width:70%"></td>
                                        </tr>
                                        <tr>
                                            <td>@Html.CheckBox("isCh4", false)4- مقدار ....</td>
                                            <td style="width:70%"></td>
                                        </tr>
                                        <tr>
                                            <td>@Html.CheckBox("isCh5", false)5- سایر موارد</td>

                                        </tr>
                                        <tr>
                                            <td>@Html.TextBox("isTxtAnswer")</td>
                                        </tr>
                                    </table>

                                    <p style="direction:ltr;text-align:left">

                                        <input type="submit" style="width:100px;height:30px;text-align:center" class="btn-beoro-1" value="ثبت" />
                                    </p>



                                </div>
                            </div>

                        </div>
                    }
                </div>
            </div>
        </div>
    </div>
</div>

کاربر سایت

rahimi.med

عضویت از 1396/08/03

  • دوشنبه 6 آذر 1396
  • 23:46

کنترلر دوم این کار

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Form.Models;
namespace Form.Controllers
{
    public class CheckDataController:Controller
    {
        public static int MyFirst = 0;
        public static int MySecond = 0;
        ALERTEntities demo = new ALERTEntities();
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Home(string First, string Second)
        {
            MyFirst = int.Parse(First);
            MySecond = int.Parse(Second);


            var ids = demo.Numbers.Find(MySecond);

            if (MyFirst > ids.Num1)
            {
                return Json("true", JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json("false", JsonRequestBehavior.AllowGet);
            }
           
        }
        public ActionResult YesAnswer()
        {



            
            ALertTable Obj = new ALertTable();
            Obj.ID = int.Parse(DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString());
            Obj.FID = MySecond;
            Obj.TextBoxID = 1;
            Obj.TextBoxValue = MyFirst;
            Obj.AlertText = "مقدار وارد شده بیشتر از مقدار مجاز نیست";
            Obj.UserAction = true;
            Obj.UserResponse = "";
            try
            {
                demo.ALertTables.Add(Obj);
                demo.SaveChanges();
            }
            catch { }

            
            return View();

            
        }
        public ActionResult RegisterAnswer(Boolean isCh1, Boolean isCh2, Boolean isCh3, Boolean isCh4, Boolean isCh5, string isTxtAnswer)
        {
            string Description = "";
            if (isCh1)
                Description += " مقدار غیر منطقی بود " + " , ";
            if (isCh2)
                Description += " مقدار قابل قبول نبود " + " , ";
            if (isCh3)
                Description += " مقدار مجاز نبود " + " , ";
            if (isCh4)
                Description += " مقدار .... " + " , ";
            if (isCh5)
                Description += "  " + isTxtAnswer + " , ";


            ALertTable Obj = new ALertTable();
            Obj.ID = int.Parse(DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString());
            Obj.FID = MySecond;
            Obj.TextBoxID = 1;
            Obj.TextBoxValue = MyFirst;
            Obj.AlertText = "مقدار وارد شده بیشتر از مقدار مجاز است";
            Obj.UserAction = false;
            Obj.UserResponse = Description;
            try
            {
                demo.ALertTables.Add(Obj);
                demo.SaveChanges();
            }
            catch { }


            return View();
        }
    }
}

کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • سه شنبه 7 آذر 1396
  • 11:49

داخل TempData قرار دهید و به کنترلر مورد نظر ارسال کنید

این لینک رو ببینید

کاربر سایت

rahimi.med

عضویت از 1396/08/03

  • سه شنبه 7 آذر 1396
  • 18:52

سپاسگزارم

کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)