MVC Html.ActionLink with post functionality?

前端 未结 3 1525
闹比i
闹比i 2021-01-16 02:43

I\'m checking to see if anyone has written an MVC extension for Html.ActionLink that you can pass in Post parameters like such:

<% Html.ActionLink(\"Click         


        
相关标签:
3条回答
  • 2021-01-16 03:00

    ActionLink is just for creating an <a>. What you are asking for would blow up if it is already inside of a form. If it isn't then it is preferable to make the link the submit button inside the form and NOT use javascript (javascript and emails don't get along great).

    You could create the form and appende it to the end of the DOM. This could be done through partial view or through javascript.

    Honestly I suggest you don't use a POST. If you persist most of the data and just have the ids needed to retrieve said data, you should never have to pass too much data in an actionlink.

    0 讨论(0)
  • 2021-01-16 03:06

    This piece of code was helpful for me and saved my day.. I improved it and it helped me for Impersonated user.. here is bellow ,what i did..

      <% if (Session["SessionUserImpersonate"] != null && Session["SessionUserImpersonate"] != "" && Session["SessionUserImpersonate"] == "Yes")
        {
            BLL.Models.User userold = new BLL.Models.User();
            userold = (BLL.Models.User)Session["SessionUserOld"];      
            %>
        <span class="FL">(Impersonated as <%=Website.Backoffice.SessionHelper.Session_User.UserName != null ? Website.Backoffice.SessionHelper.Session_User.UserName:"" %>  , </span>
    
        <form class="FL" id='frmid' action="/Index/Login?username=<%=userold.UserName%>&password=<%=userold.Password%>&IsImpersonate=No"  method="post">
                    <a class="TxtRed" style="cursor:pointer;" onclick="$('#frmid').submit(); return false;" > - finish impersonated session  </a>
                    </form>   
                    ) &nbsp;&nbsp;
        <%} %> 
    
    0 讨论(0)
  • 2021-01-16 03:10

    Ajax.ActionLink works perfectly fine for a post request. To refresh page, you can create a function that refreshes page (e.g. function reload(){ windows.location.reload();}). It would look something like this.

    @Ajax.ActionLink("DiaplyName", "Action", new { parameters to post }, new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, OnComplete="reload();"})
    

    Note: You'll need to reference the appropriate scripts to use ajax or jQuery code.

    0 讨论(0)
提交回复
热议问题