Click here to Skip to main content
15,907,396 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
--Scenario

I have a upload and save button. Both are of type "submit".

Both the button calls their respective Action method in controller. Actually the upload button should be there in first begin form.

But I have used two begin form. One for save part. And the other for upload part. The second begin form starts just after the first begin form.

So this way the functionality is working. But As the upload button is moved to second begin form which is just after the first begin form so the button is coming just below of the page. Ideally it should remain somewhere in the middle of the page i.e in first beginform.

Now As these are two begin form, I cannot use CSS/styles to move the upload button to middle of the page.

---
I tried with Partial view. I kept the second beginform in partial view. And rendered the patial view in the first beginform. The UI was fixed. But when I clicked upload button it called First beginform(action method).

--First begin form

C#
@using (Html.BeginForm("UploadStoresDetails", "QueryAnalyzer", FormMethod.Post, new { id = "userform", enctype = "multipart/form-data" }))
{
...
...
...
}


--second begin form

@using (Html.BeginForm("UploadFile", "QueryAnalyzer", FormMethod.Post, new { id = "userform1", enctype = "multipart/form-data" }))
{
    <input type="file" name="UploadedFile" accept="*.csv,*.txt" id="UploadFiles" style="width: 200px" />
    <input type="submit" value="Upload" name="UploadFile" id="Upload" />
}


-------controller method(first beginform)-----
public ActionResult UploadStoresDetails(FormCollection jobDetails, string command, HttpPostedFileBase UploadedFile)
        {

            
            JobViewModel jobFullData;
            Job jobDatafromView;
            JobSchedulerViewModel jobSchedularDataFromView;
            if (ModelState.IsValid)
            {
  
                if (command == "Save Job")
                {
                    
                    ...

                }
               
               
            }
            return RedirectToAction("CloneJob", "QueryAnalyzer", new { JobID =Convert.ToInt32( TempData["JobId"] )});
           
        }

-------------Second Action result

C#
[HttpPost]

        public ActionResult UploadFiles(HttpPostedFileBase UploadedFile)
        {
            var Jsfinal="";
            var result = GetStoreTillsDetailsByUpload();
            Jsfinal = (result.Data).ToString().Replace("classcheck", "class");
            if ((TempData["InvalidStore"] != string.Empty))
            {
                return Json(TempData["InvalidStore"], JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(Jsfinal, "text/html");

            }


        }



--kindly help to overcome this problem as I am new to MVC 4.
Posted

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