【问题标题】:How to show Popup in MVC3如何在 MVC3 中显示弹出窗口
【发布时间】:2012-06-28 16:15:01
【问题描述】:

我是 MVC 新手。如何在弹出式 MVC3 razor 中编辑数据。我看了很多,但没有明白。 我正在使用 jquery。 我的控制器-

[HttpGet]
    public ActionResult Edit(int id)
    {

        var q = from p in db.accs
                where p.id == id
                select p;
        return View(q.FirstOrDefault());
    }
    [HttpPost]
    public ActionResult Edit(int id,account ac)
    {
        acc a = (from p in db.accs
                     where p.id==id
                     select p).Single();

        if (ModelState.IsValid)
        {
            a.f_name = ac.f_name;
            a.l_name = ac.l_name;
            a.Address = ac.Address;
            a.Phoneno = ac.Phoneno;
            db.SubmitChanges();
            int i = 2;
            return RedirectToAction("Display", new { i = i });
        }
        else
        {
            return View("Edit");
        }

【问题讨论】:

  • 什么意思?你想有一个弹出窗口或弹出 div 里面有一个表单吗?你希望它是 ajax 还是普通的 POST?
  • 我只是想通过验证来编辑详细信息,但我不知道怎么做?

标签: asp.net-mvc-3 razor popup


【解决方案1】:

您可以查看jQuery UI dialog 组件,它可以让您实现这一目标。

【讨论】:

    【解决方案2】:

    您必须使用 Ajax.ActionLink 可以返回部分视图,然后将该结果添加到 div 中,然后 OnSuccess 显示该部分视图。


     @Ajax.ActionLink("popup", "SomeAction", new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "result",     InsertionMode = InsertionMode.Replace, OnSuccess="openPopup" })<br />
    
       <div id="result" style="display:none;"></div>
    
       <script type="text/javascript">
           $(document).ready(function() {
              $("#result").dialog({
                 autoOpen: false,
                   title: 'Title',
                  width: 500,
                 height: 'auto',
                modal: true
            });
       });
           function openPopup() {
             $("#result").dialog("open");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多