TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ritendra Mall
NA
316
33.2k
How to pass data from view to controller using model binding
Aug 21 2019 1:18 AM
Hello,
Please help to understand how pass view values to controller as parameters on clicking of filter button below is my code sample
View
@model UniPro.Web.Models.EmployeeDashboardModel
@{
ViewBag.Title =
"EmployeeList"
;
Layout =
"~/Views/Shared/_Layout.cshtml"
;
}
<h2>LocationList</h2>
@using (Html.BeginForm(
"filterLOV"
,
"EmployeeLocationList"
, FormMethod.Get))
{
<div
class
=
"contentbox"
>
<p
class
=
"contentboxheading"
>
@ViewBag.Title
</p>
<div
class
=
"contentbox_innercontent"
>
<table width=
"100%"
>
<tr>
<td >
@Html.Hidden(
"ID"
,Model.EmpListLOV,
new
{ id =
"empID"
})
<label
class
=
"highlightlabel"
>ID</label>
</td>
<td >
@Html.DevExpress().TextBox(
txtsetting =>
{
txtsetting.Name =
"txtemployeeID"
;
txtsetting.ClientEnabled =
true
;
txtsetting.Width = System.Web.UI.WebControls.Unit.Pixel(150);
txtsetting.Height = System.Web.UI.WebControls.Unit.Pixel(25);
txtsetting.Properties.MaxLength = 50;
().value); }";
}).GetHtml()
</td>
<td >
<label
class
=
"highlightlabel"
>Name</label>
</td>
<td >
@Html.Hidden(
"Name"
, Model.EmpListLOV,
new
{ id =
"hiddenName"
})
@Html.DevExpress().TextBox(
txtsetting =>
{
txtsetting.Name =
"txtemployeeName"
;
txtsetting.ClientEnabled =
true
;
txtsetting.Width = System.Web.UI.WebControls.Unit.Pixel(150);
txtsetting.Height = System.Web.UI.WebControls.Unit.Pixel(25);
txtsetting.Properties.MaxLength = 50;
}).GetHtml()
</td>
<td >
<label
class
=
"highlightlabel"
>Age</label>
</td>
<td >
@Html.Hidden(
"Age"
, Model.EmpListLOV,
new
{ id =
"hiddenAge"
})
@Html.DevExpress().TextBox(
txtsetting =>
{
txtsetting.Name =
"txtemployeeAge"
;
txtsetting.ClientEnabled =
true
;
txtsetting.Width = System.Web.UI.WebControls.Unit.Pixel(150);
txtsetting.Height = System.Web.UI.WebControls.Unit.Pixel(25);
txtsetting.Properties.MaxLength = 50;
}).GetHtml()
</td>
<td >
<label
class
=
"highlightlabel"
>Maritial Status</label>
</td>
<td >
@Html.Hidden(
"EMPMaritial_Status"
, Model.maritial_StatusList,
new
{ id =
"hiddenstatus"
})
@Html.DevExpress().ComboBox(
settings =>
{
settings.Name =
"drostatus"
;
settings.Width = System.Web.UI.WebControls.Unit.Pixel(100);
//settings.Style.Add("width", "85");
settings.Properties.DropDownStyle = DevExpress.Web.ASPxEditors.DropDownStyle.DropDownList;
settings.Properties.TextFormatString =
"{0}"
;
settings.Properties.ValueType =
typeof
(string);
settings.Properties.ValueField =
"ID"
;
settings.Properties.TextField =
"EMPMaritial_Status"
;
}).BindList(Model.maritial_StatusList).GetHtml()
<td >
<label
class
=
"highlightlabel"
>Location</label>
</td>
<td >
@Html.Hidden(
"EMP_Location"
, Model.LocationLOV,
new
{ id =
"hiddenLocation"
})
@Html.DevExpress().ComboBox(
settings =>
{
settings.Name =
"droLocation"
;
settings.Width = System.Web.UI.WebControls.Unit.Pixel(100);
//settings.Style.Add("width", "85");
settings.Properties.DropDownStyle = DevExpress.Web.ASPxEditors.DropDownStyle.DropDownList;
settings.Properties.TextFormatString =
"{0}"
;
settings.Properties.ValueType =
typeof
(string);
settings.Properties.ValueField =
"ID"
;
settings.Properties.TextField =
"EMP_Location"
;
}).BindList(Model.LocationLOV).GetHtml()
</td>
<td >
<input type=
"button"
name=
"btnSearch"
id=
"btnFilter"
value=
"Apply Filter"
class
=
"buttoncss"
title=
"Click for Search"
style=
"width: 100px;"
/>
</td>
</tr>
</table>
</div>
<div align=
"center"
style=
"margin-top:3%"
id=
"container"
>
@Html.Partial(
"EmplyeeDemoGridPartial"
, Model.EmpListLOV)
</div>
</div>
}
controller
public
ActionResult FilterLOV(
int
? txtemployeeID,
string
txtemployeeName,
int
? txtemployeeAge,
int
? droLocation)
{
List<EmployeeDemoObjectDomain> empSearch =
new
List<EmployeeDemoObjectDomain>();
IEmployeeDemoBusinessService empSearchBS =
new
EmployeeDemoBusinessService();
empSearch = empSearchBS.GetEmployeeByFilter(txtemployeeID, txtemployeeName,txtemployeeAge, droLocation);
return
PartialView(
"EmplyeeDemoGridPartial"
, empSearch);
}
Model
public
class
EmployeeDashboardModel
{
public
List<EmployeeDemoObjectDomain> EmpListLOV {
get
;
set
; }
public
List<LocationLOV> LocationLOV{
get
;
set
;}
public
List<Maritial_StatusDemoList> maritial_StatusList {
get
;
set
; }
}
Firstly i was using ajax call to pass the data from the view to controller but i want to do the same with model binding.
Please suggest.
Reply
Answers (
2
)
localization in diff languages
Saving and reporting datetime & timezone info in database