Rohit
Rohit

Reputation: 6623

Calling Post method using HTML.ActionLink

I have read multiple posts on similar issue but did not work.

I have fixed footer buttons and facing issue in calling "Post" version Edit action in Project controller. Here is what I'm trying to do

Error

Let me know if question needs further explaination.

(I tried using Ajax.ActionLink which is suggested in multiple posts too but did not work out.

Similar Question

Upvotes: 3

Views: 24316

Answers (1)

Rohit
Rohit

Reputation: 6623

Finally I managed to fix it by some workarounds. Posting solution here to help someone.

Like I said earlier, I tried using Ajax.ActionLink but I was not able to achieve the same. Instead I looked for Calling Form Submit action from outside of form that's what I actually need here.

Form: Name your Form something, say "editProjDetailsForm"
@using (Html.BeginForm(null, null, FormMethod.Post,
new { @class = "form-horizontal",
name = "editProjDetailsForm" }))

Footer: Call this method from the footer button.

<input type="button" onclick="document.editProjDetailsForm.submit();" 
       class="btn btn-primary"
       value="Save Changes" />

I tried this one too in footer but it did not workout:

@Ajax.ActionLink("Save Changes", "Edit", new { id = Model.ProjectId }, 
              new AjaxOptions { HttpMethod = "POST" })

Helpful Posts

  1. Naming A form using Begin Form
  2. Submit Button outside HTML.BeginForm
  3. Submit Button outside HTML.BeginForm (another link)
  4. ASP.net ActionLink and POST Method
  5. Error in case you have parameterized constructor in ViewModel and did not declare parameterless constructor

Display Issue if you are using bootstrap In footer I had one input type = button and one action link with class= button. Both nested in one btn-group but there height were appearing different as visible in following snapshot:

Different buttons

Fix: Found that it is a known issue and there is one suggested solution but did not work out much for me (i.e. for Internet Explorer). input type=submit and anchor button in btn-group appear as different sizes

Solution: add .btn { line-height:normal!important; } or if you want to do only for a specific button lets say the above input button then do this:

<input type="button" onclick="document.editProjDetailsForm.submit();" 
     class="btn btn-primary"
     value="Save Changes" 
     style="line-height:normal!important;" />

Upvotes: 7

Related Questions