只在按钮点击mvc3中的同一页面时加载另一个View页面

时间:2014-03-13 07:18:17

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

下面是我的视图页面,我在其中调用了行动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中的操作。我想做的事情就是每当我从下拉列表中选择albumname和歌曲名称时,当我点击按钮时我的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");
        }
    }

1 个答案:

答案 0 :(得分:0)

 @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

运作良好