Click here to Skip to main content
16,004,761 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hi all,

I am new to Asp.net mvc. so i need some help.

In my project there is a view called programlist, in that there is a link "Add Program". When we click on that link i am showing a partial view as popup using jquery.
In that partial view there is one fileupload control and some textbox controls are there. when user clicks the save button then i wrote this code.

JavaScript
$("#frmadd").submit();


here frmadd is id of the form in partialview.

when that form is submitted a action method with return type as jsonresult will get executed.Now i want to catch that json result in script, but it is opening as "Open/Save" Dialog in browser.
Now what should i do to catch that result in script.

Please help me.
Posted
Updated 30-Jan-12 23:45pm
v4

1 solution

When you have specified an action, the action gets executed and the action results(ActionResult or JsonResult) should send response back. See below example.
User is provided two radios: Add/Replace & Delete Image. When user selects either option and select upload file then click on button will call "SaveMyImage" action in the controller.
JavaScript
  <form id="frmImg" action="@Url.Action("SaveMyImage")" method="post" enctype="multipart/form-data">
  <table>
    <tr>
     <td>
         <input type="radio" name="addReplaceImage" value="1" checked="checked"/>Add/Replace Image<br />
     <input type="radio" name="addReplaceImage" value="2"/>Delete Image
    </td>
  </tr>
     <tr>
       <td><input type="file" id="fileImage" name="fileImage" value=""/></td>
     </tr>
  </table>
</form>

//Controller action        
  [HttpPost]
  public ActionResult SaveMyImage(int addReplaceImage, HttpPostedFileBase fileImage)
        {
           //save image then return partial view data
	   
        }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900