Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
189 views
in Technique[技术] by (71.8m points)

c# - I have no idea for Yes or No Message box asp.net Mvc

I made Yes or No message box using JavaScript. also I use Model List view, but it can select only first item from my model like "Yes". Second and third item could not select any "Yes" value to my controller. Second and third item are Null value for my Controller.

<section id="testimonials" class="testimonials">
    <div class="container" data-aos="fade-up">
        <div class="section-title">

            <h2>Point Gift</h2>



            <div class="row product-container">
                @foreach (var item in Model)
                {
                    <div class="col-md-3 col-sm-3 col-xs-6" style="margin-bottom:0px">
                        <div class="thumbnail product-item" style="height:400px">

                         
                            <embed 
      src="~/PointGfIM/@item.Point_Url#toolbar=0&navpanes=0&scrollbar=0" style="width: 220px; 
         height: 210px;" class="with-200" />

                            <div class="caption">
                                <h5>@item.Point_Name</h5>
                                <h2>@item.Point_Point</h2>

                                @using (Html.BeginForm("CustomList", "Point_Item", new { 
                            productId = item.Pid, url = "CustomList" }, FormMethod.Post))
                                {
                                 <input type="submit" value="Submit" onclick="Confirm()" />
                                } 
                            </div>
                        </div>
                    </div>
                }


            </div>
        </div>
    </div>
</section>

   <script type="text/javascript" 
     src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
     <script type="text/javascript">
       function Confirm() {
           var input = $("<input />");
          input.attr("type", "hidden").attr("name", "confirm_value");
           if (confirm("Are you sure you want to buy it?")) {
               input.val("Yes");
           } else {
          input.val("No");
       }
        $("form")[0].appendChild(input[0]);
      }
     </script>

Controller.

    public ActionResult CustomList(string confirm_value, int productId, string 
    url)//Confirm_Value is null ?? why?
    {



        var temor = db.Point_Item.Where(x => x.Pid == productId).FirstOrDefault();
        var Username5 = User.Identity.Name;

        var ok1 = db.Users.Where(x => x.UserName == Username5).FirstOrDefault();

        if (confirm_value == "Yes")
        {
            if(ok1.User_Point - temor.Point_Point < 0)
            {
                TempData["Notenouth1"] = "Email is not matched";
            }
            else
            {
                ok1.User_Point = ok1.User_Point - temor.Point_Point;
                db.SaveChanges();
            }
            
        }
        else
        {
            ViewBag.Message = "You clicked NO!";
        }
        return RedirectToAction(url);
       
    }

If I click "Yes", confirm_value in my Parameter from CustomList become "null" value.

question from:https://stackoverflow.com/questions/65893040/i-have-no-idea-for-yes-or-no-message-box-asp-net-mvc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...