Send data from partial view to controller and vice versa - ASP.NET MVC 5

Hi All,

This is my first MVC application. I have a view(SupportCaseSystem.cshtml) which has 3 parts.

1. Employee Details - Search Textbox, Name,Email, Department,Phone(When employeeid is entered in textsearchbox the details should be populated via AJAX)
2. Manager Details - Same as above
3. FindSupportCases Button and Grid. - When Clicked on the button supportcases currently allocated to the selected employee id should be retrieved and displayed in grid using Ajax.

I created two viewmodels and two partial views.
GetEmployeeDetailsViewModel
----------------------------------------------------
public class GetEmployeeDetails
{
public  string empid {get;set;}
public  string Name {get;set;}
public  string Email {get;set;}
public  string Department {get;set;}
public  string Phone {get;set;}
}

GetSupportCasesViewModel
public class GetSupportCasesViewModel
{
public  string empid {get;set;}
public int casenumber {get;set;}
public DateTimeSubmitted {get;set;}
public string casedetails {get;set;}
}
GetEmployeeDetailsPartialView
-------------------------------------------------
@model EMS.GetEmployeeDetailsViewModel
<div>
</div>

GetSupportCasesPartialView
-------------------------------------------------
@model EMS.GetSupportCasesViewModel
<div>
--populate webgrid here
</div>

Controller
-------------------
public ActionResult  GetEmployeeDetailsById(string empid)
{
 var EmplVM = new GetEmployeeDetailsViewModel()
EmployeeFacade Efac = new EmployeeFacade();
Employee emp = Efac.GetInfo(empId);
EmplVM.Name = emp.Name;
.
.
.
return view(EmplVM);

}
Similar way written for get support cases.

Open in new window


Below are my questions.

1. In my main view file SupportCaseSystem.cshtml how do i embed these partial views? The first partial view needs to be used twice once for employee and once for manager. The second partial view is grid to show tickets.

2. When view loads initially only the first partial view for employee and manager should be visible with their values as blank. After user enters emp id i need to fill the details by Ajax call.  Same for manager details.

Now how do i send the empid from partial view to my controller ? 1. by using Ajax and 2. by not using Ajax.
2. How do i bind the returned data to the controls in partial view ?

Hope i am clear. Thanks for your time and any help is appreciated.
JyozealAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gautham JanardhanCommented:
ideally u rener partial view like shown below

@{ Html.RenderPartial("someview.cshtml", passtheModelHere);}

Open in new window


This is if you are not going to laod data using ajax.

If you are using ajax then pass an empty model to the view so tht u can render the view and then set the control values on ajax  call back

or

Use .load () method of jquery to render the view directly by passing the employee id (here the loading of data should be handled inside the partial view).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JyozealAuthor Commented:
thanks for your comment. Where should i provide the Ajax code? I added it in partial view but its not getting called. Only if its in partial view i can use it somewhere else too.

I am trying to create a partial view which consists of once search box search button and table with details. Whenever an employee id is entered and search clicked it goes to my controller and get the details back.

When i tried this javascript written inside partial view doesn't seem to work. Any idea about this? Also if you could post some code..
0
Gautham JanardhanCommented:
how are u adding in the partial? It shud get called even if its in the partial code
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

JyozealAuthor Commented:
thanks for your comment. I included script tag in the partial view like below.

<script type="text/javascript">

jquery ajax call here

</script>
0
JyozealAuthor Commented:
there is no error in my ajax code. Its working from main view.
0
Gautham JanardhanCommented:
can you post some of your code in the partial view.
0
JyozealAuthor Commented:
That answer helped.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.