使用<a href="">

时间:2018-11-08 07:41:46

标签: javascript c# ajax asp.net-mvc post

I have a two ActionMethods for Get and Post . and in Post I am getting the ID and returning the result to another view. Here it is my Action Methods

 public ActionResult Select()
    {
        if (!General.ValidateSession())
        {
            return RedirectToAction("Login", "User");
        }
        return View();
    }
    [HttpPost]
    public ActionResult Select(int id)
    {
        if ((int)Session["DepartmentID"] != id && Session["Role"].ToString() != "ADMIN" && Session["Role"].ToString() != "FUNCTIONAL HEAD" )
        {
            ViewData["norights"] = "toAccess";
            return View("NoAccess");
        }
        var Result = safetyFile.getSelectedDepartmentFiles(id).Select(x => new ViewModel.SafetyFileViewModel   //Notification 
        {
            ID = x.ID,
            UploadedBy = x.UploadBy,
            FileDescription = x.FileDesscription,
            UploadedDate = x.UploadedDate,
            DepartmentFor = depRep.SelectByID(x.DepartmentID).Department,
            FileCategory = category.SelectByID(x.FileCategoryID).CategoryName,
            SafetyFileName = x.MultipleFile

        });
        return View("ListDocuments", Result);
    }

Here It is my View for this method.

<form id="search" method="post">
<a href="/file/select/1" onclick="this.form.submit()">HSEQ Document</a>
<a href="/file/select/2" onclick="this.form.submit()">HSEQ Document</a>
<a href="/file/select/3" onclick="this.form.submit()">HSEQ Document</a>
</form>

I want to post from href link , Like I am having different ID in each href.

Whenever I clicked anchor tag it call get method.

I tried @Ajax.ActionLink and was working fine but that approach didn't return another view from post method that is ListDocument.

In Short: I want to call a post method every time i click Anchor tag.

0 个答案:

没有答案