选中复选框后更改视图 [英] change a view after checked a checkbox

查看:79
本文介绍了选中复选框后更改视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图,可以在不更改整体视图的情况下更改内容,
(更改视图的一部分)
这是我的代码:

型号:

I have a view that changes content without changing the overall view,
(change a portion of the view)
here is my code:

Models:

public class DisplayData
    {
        public int ID { get; set; }
        public DisplayData(int ID)
        {
            this.ID = ID;
        }
    }



控制器:




Controllers:


public ActionResult PartialDemo(string Data)
        {
            List<DisplayData> Display = new List<DisplayData>();

            if (Request.IsAjaxRequest())
            {
                if (Data == "1")
                {
                    Display.Add(new DisplayData(3));
                    Display.Add(new DisplayData(4));
                }
                else
                {
                    Display.Add(new DisplayData(5));
                    Display.Add(new DisplayData(6));
                }
                return PartialView("PartialDemoUC", Display);
            }
            else
            {
                Display.Add(new DisplayData(1));
                Display.Add(new DisplayData(2));
                return View("PartialDemo", Display);
            }
        }



PartialDemoUC.cshtml



PartialDemoUC.cshtml

@model IEnumerable<dynamic>
 
@foreach(var items in Model)
{
   @items.ID    
}



PartialDemo.cshtml:



PartialDemo.cshtml:

@model IEnumerable<AppTwitter.Models.DisplayData>
@{
    ViewBag.Title = "PartialDemo";
}
 
<script src="../../Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
@Ajax.ActionLink("Link_1", "PartialDemo", "PartialDemo", new {Data= "1" }, new AjaxOptions { UpdateTargetId = "rsvpmsg" })
@Ajax.ActionLink("Link_2", "PartialDemo", "PartialDemo", new {Data= "2" }, new  AjaxOptions { UpdateTargetId = "rsvpmsg" })
 
<div id="rsvpmsg">
@{ Html.RenderPartial("PartialDemoUC", this.Model);}
</div>




我将通过一个复选框更改Link_1和Link_2:如果选中了chechbox,则就像单击链接一样
我该怎么办?

对不起,我的英语不好

谢谢,




I will change Link_1 and Link_2 by a checkbox: if chechbox is checked it''s like the link is clicked
how can i do this ?

I am sorry for my bad english

Thanks,

推荐答案

基本上,您想使用jQuery观看复选框上的click事件.单击它时,您希望jQuery方法使用适当的参数调用MVC方法.这是一个堆栈溢出问题,在给定的答案中有一个如何执行此操作的示例:

http://stackoverflow.com/questions/9185606/how-to-trigger-an-ajax-event-with-a-checkbox-click-in-asp-net-mvc [
Basically, you want to use jQuery to watch the click event on the checkbox. When it is clicked, you want to have the jQuery method call your MVC method with the appropriate parameters. Here is a Stack Overflow question that has an example of how to do this in the given answer:

http://stackoverflow.com/questions/9185606/how-to-trigger-an-ajax-event-with-a-checkbox-click-in-asp-net-mvc[^]


这篇关于选中复选框后更改视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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