【问题标题】:load another View page only on button click on the same page in mvc3仅在按钮上加载另一个查看页面单击mvc3中的同一页面
【发布时间】:2014-03-13 07:18:16
【问题描述】:

下面是我的视图页面,我在其中调用了操作 PromotionalMis,在此视图代码下方我编写了我的操作

@using (Html.BeginForm("PromotionalMis", "Home", FormMethod.Post))
{
    <div class="loginn" style="width:600px;">
       <div class="logintext" style="width:154px;">
          @Html.LabelFor(model => model.SongId, "Song Name")
      </div>
      <div class="mistype">
      <select id="ddlsongs" name="ddlsongs" class="state" required="required">
      </select>
      </div>
    </div>
    <div class="loginn" style="width:600px;">
       <div class="logintext" style="width:154px;">
         &nbsp;
       </div>
    <div class="generate">
       <input type="submit" name="button" value="Generate" id="btn"/> 
    </div>
  </div>  

}

以下是我在 Home Controller 中的操作。我想做的事情是,每当我从下拉列表中选择专辑名称和歌曲名称以及单击按钮时,我的 PromotionalMis 视图页面应该在同一页面上可见

   [HttpPost]
    public ActionResult PromotionalMis(string ddlsongs)
    {

        if (Session["user"] != null && Session["user"].ToString() == "MISADMIN")
        {
            if (ddlsongs != "0")
             {                  
                string sSongName = "";
                int iId = Convert.ToInt32(ddlsongs);
                List<CRBT_Promotion> ss = new List<CRBT_Promotion>();
                using (crbt_onwebEntities dbcontext = new crbt_onwebEntities())
                {
                    ss = (from z in dbcontext.CRBT_Promotion where z.id == iId select z).ToList();
                }
                foreach (var ssname in ss)
                {
                    sSongName = ssname.SongName.ToString();
                }
                Session["ss"] = sSongName;
                ViewBag.songformis = sSongName;
            }
            return PartialView("PromotionalMis");  
        }
        else
        {
            return RedirectToAction("LogOn");
        }
    }

【问题讨论】:

  • 使用 ajax.beginform。发布你到目前为止尝试过的内容!
  • 是的..但它不起作用..请给我另一个选项或代码?
  • 请提供您的 Ajax.BeginForm 的代码
  • 您好先生...我有解决方案...非常感谢...

标签: c# asp.net asp.net-mvc-3 razor


【解决方案1】:
 @using (Ajax.BeginForm("ActionName", "Home", new AjaxOptions {HttpMethod="POST", UpdateTargetId = "filesBody" ,InsertionMode = InsertionMode.Replace}))
{
<div class="loginn" style="width:600px;">
<div class="logintext" style="width:154px;">
 @Html.LabelFor(model => model.SongId, "Song Name")
 </div>
 <div class="mistype">
<select id="ddlsongs" name="ddlsongs" class="state" required="required">
</select>
</div>
</div>
<div class="loginn" style="width:600px;">
<div class="logintext" style="width:154px;">
&nbsp;
 </div>
 <div class="generate">
<input type="submit" name="button" value="Generate" id="btnclick"/> 
</div>
</div>  
     }
     <div id="filesBody"></div

效果很好

【讨论】:

    猜你喜欢
    • 2021-08-19
    • 1970-01-01
    • 1970-01-01
    • 2015-10-16
    • 2015-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    相关资源
    最近更新 更多