no idea which part is wrong. I have successfully display the list of checkbox inside the view but when it is post back to the controller the CheckBoxViewModel model return null. ASP.NET MVC
public class CheckBoxViewModel {
public List<CheckBoxList> CheckBoxLists {get; set;}
}
public class CheckBoxList{
public int CheckBoxId {get; set;}
public string CheckBoxDescription { get; set;}
public bool CheckBoxState {get; set;}
}
#model CheckBoxViewModel
foreach(var item in Model.CheckBoxLists) {
#Html.CheckBoxFor(model => model.CheckBoxState, new { id = #model.CheckBoxId }):
#Html.DisplayFor(model => model.CheckBoxDescription);
}
[HttpPost]
public ActionResult EditCheckBox(int userId, CheckBoxViewModel model) {
}
Here goes the complete solution -
I used your same ViewModels -
public class CheckBoxViewModel
{
public List<CheckBoxList> CheckBoxLists { get; set; }
}
public class CheckBoxList
{
public int CheckBoxId { get; set; }
public string CheckBoxDescription { get; set; }
public bool CheckBoxState { get; set; }
}
then I created on GET Action with some sample data -
public ActionResult AddQuestion()
{
CheckBoxViewModel m = new CheckBoxViewModel();
m.CheckBoxLists = new List<CheckBoxList>();
m.CheckBoxLists.Add(new CheckBoxList() { CheckBoxDescription = "Hi1", CheckBoxId = 1, CheckBoxState = true});
m.CheckBoxLists.Add(new CheckBoxList() { CheckBoxDescription = "Hi2", CheckBoxId = 2, CheckBoxState = true });
m.CheckBoxLists.Add(new CheckBoxList() { CheckBoxDescription = "Hi3", CheckBoxId = 3, CheckBoxState = true });
return View(m);
}
The corresponding GET View -
#model WebApplication1.Controllers.CheckBoxViewModel
#{
ViewBag.Title = "AddQuestion";
}
<h2>AddQuestion</h2>
#using (Html.BeginForm("EditCheckBox", "Home"))
{
for (int i = 0; i < Model.CheckBoxLists.Count; i++)
{
#Html.CheckBox(
String.Format("CheckBoxLists[{0}].CheckBoxState", i.ToString()),
Model.CheckBoxLists[i].CheckBoxState,
new { id = Model.CheckBoxLists[i].CheckBoxId })
#Html.Label(Model.CheckBoxLists[i].CheckBoxDescription)
#Html.Hidden(String.Format("CheckBoxLists[{0}].CheckBoxDescription", i.ToString()), Model.CheckBoxLists[i].CheckBoxDescription)
#Html.Hidden(String.Format("CheckBoxLists[{0}].CheckBoxId", i.ToString()), Model.CheckBoxLists[i].CheckBoxId)
}
<input type="submit" value="Click" />
}
Then finally the POST Action -
[HttpPost]
public ActionResult EditCheckBox(int? userId, CheckBoxViewModel model)
{
return null;
}
Here is the look of the page -
When I ran the code and hit the button, I get the model as shown below -
Related
This is my first ask. I have 2 models for 1 view. I built the code but i have a problem. data comes null from view to controller.
Models:
Mom model:
public class BildirimOlusturViewModel
{
public BildirimOlusturModel bildirimOlusturModel { get; set; }
public TagBoxViewModel tagBoxViewModel { get; set; }
}
Child models:
public class BildirimOlusturModel
{
[Required(ErrorMessage = "Lütfen bildirim tipi seçiniz")]
public string BildirimTipi { get; set; }
[Required(ErrorMessage = "Lütfen alıcı tipi seçiniz")]
public string AliciTipi { get; set; }
[Required(ErrorMessage = "Lütfen alıcı seçiniz")]
public string Alicilar { get; set; }
[Required(ErrorMessage = "Lütfen bir başlık giriniz")]
public string Baslik { get; set; }
[Required(ErrorMessage = "Mesaj boş olamaz")]
public string Mesaj { get; set; }
}
public class TagBoxViewModel
{
public List<string> Items { get; set; }
}
View:
#model xyz.Web.Notifications.Models.BildirimOlusturViewModel
<form method="post" asp-controller="Bildirim" asp-action="BildirimOlustur">
...
#(Html.DevExtreme().SelectBoxFor(s => s.bildirimOlusturModel.AliciTipi)
.Placeholder("Alıcı Tipi...")
.DataSource(new List<SelectListItem> {
new SelectListItem
{
Text = "Personel",
Value = "personel".ToString()
},
new SelectListItem
{
Text = "Müşteri",
Value = "musteri".ToString()
}})
.ValueExpr("Value").DisplayExpr("Text")
.OnValueChanged("alicitipi_changed")
.ID("slcAliciTipi")
)
</div>
<div class="col-md-8">
#(Html.DevExtreme().TagBoxFor(x => x.bildirimOlusturModel.Alicilar)
.Items(Model.tagBoxViewModel.Items)
.SearchEnabled(true)
.Placeholder("Alıcı...")
.ID("TagBoxAlici")
)
#(Html.DevExtreme().TextBoxFor(x => x.bildirimOlusturModel.Baslik)
.Placeholder("Başlık...")
)
<input type="text" id="Mesaj" asp-for="bildirimOlusturModel.Mesaj" name="bildirimOlusturModel.Mesaj" id="bildirimOlusturModel.Mesaj"/>
#(Html.DevExtreme().Button()
.Text("Submit")
.Type(ButtonType.Default)
.StylingMode(ButtonStylingMode.Contained)
.Width(120)
.UseSubmitBehavior(true)
)
</form>
Controller:
[HttpPost]
public IActionResult BildirimOlustur(BildirimOlusturModel model)
{
string sAlicilar = model.Alicilar;
string sAliciTipi = model.AliciTipi;
string sBaslik = model.Baslik;
string sBildirimTipi = model.BildirimTipi;
string sMesaj = model.Mesaj;
}
Submit button sends me inside the post method but not sends the model. My variables coming null. Thank you for help.
Try adding a [FromBody] attribute before your argument.
public IActionResult BildirimOlustur([Frombody] BildirimOlusturModel model)
I solved the problem. controller was waiting for the wrong parameter.
[HttpPost]
public IActionResult BildirimOlustur(BildirimOlusturViewModel model)
{
BildirimOlusturModel mdl = new BildirimOlusturModel();
mdl = model.bildirimOlusturModel;
string sAlicilar = mdl.Alicilar;
}
I have a view model containing the information that I am using for a drop-down list on a view:
public class AddPlayersToGame
{
public string GameTitle { set; get; }
public int GameID { set; get; }
public List<SelectListItem> Players { set; get; }
public int PlayerID { get; set; }
public int[] SelectedPlayers { set; get; }
}
This is my View which simply displays a drop-down list containing the list of Players to select from:
#model WebGameProj.ViewModels.AddPlayersToGame
<div>
{
#Html.DropDownListFor(x => Model.PlayerID, Model.Players)
<input type="submit" />
}
</div>
This is the controller methods I am using:
public ActionResult AddPlayersView(int id)
{
var GameSelected = db.Games.Find(id);
if (GameSelected== null)
{
return HttpNotFound();
}
var np = new AddPlayersToGame { GameID = id, GameTitle = GameSelected.GameTitle };
np.Players = db.Players.Select(m => new SelectListItem
{
Text = m.PlayerUserName,
Value = m.PlayerId.ToString()
}).ToList();
return View(np);
}
[HttpPost]
public ActionResult AddPlayersView(AddPlayersToGame model)
{
foreach (var item in model.SelectedPlayers)
{
var SelPlayer = db.Players.Find(model.PlayerID);
if (SelPlayer== null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
if (SelPlayer != null)
{
Game GameSelected = new Game();
GameSelected.GamePlayers.Add(SelPlayer);
db.Entry(GameSelected).State = EntityState.Modified;
db.SaveChanges();
}
}
return RedirectToAction("GameDetailsView");
}
So, basically I want to have a view that displays a drop-down list of players and when some players are selected the post method will then find each player on the database by using their ids that are being passed back via the drop-down list on the view, then add them to a the current list of players for that game.
Change your model to
public class AddPlayersToGame
{
public string GameTitle { set; get; }
public int GameID { set; get; }
public int PlayerID { get; set; }
public int[] PlayerIds { set; get; }
public List<SelectListItem> Players { set; get; }
}
And your view to
#model WebGameProj.ViewModels.AddPlayersToGame
<div>
{
#Html.ListBoxFor(x => x.PlayerIds, Model.Players)
<input type="submit" />
}
</div>
You should then have the selects ids in the model after submitting.
You can also try:
Model
public class AddPlayersToGame
{
public string GameTitle { set; get; }
public int GameID { set; get; }
public int[] PlayerIDs { get; set; }
public MultiSelectList Players { get; set; }
}
Controller
public ActionResult AddPlayersView(int id)
{
var GameSelected = db.Games.Find(id);
if (GameSelected== null)
{
return HttpNotFound();
}
var np = new AddPlayersToGame { GameID = id, GameTitle = GameSelected.GameTitle };
var playerList = db.Players.Select(m => new
{
PlayerUserName = m.PlayerUserName,
PlayerId = m.PlayerId
}).ToList();
np.Players = new MultiSelectList(playerList, "PlayerIDs", "PlayerUserName");
return View(np);
}
[HttpPost]
public ActionResult AddPlayersView(AddPlayersToGame model)
{
foreach (var playerID in model.PlayerIDs)
{
var SelPlayer = db.Players.Find(playerID);
if (SelPlayer== null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
if (SelPlayer != null)
{
Game GameSelected = new Game();
GameSelected.GamePlayers.Add(SelPlayer);
db.Entry(GameSelected).State = EntityState.Modified;
db.SaveChanges();
}
}
return RedirectToAction("GameDetailsView");
}
View
#model WebGameProj.ViewModels.AddPlayersToGame
<div>
{
#Html.ListBoxFor(x => x.PlayerIDs, Model.Players)
<input type="submit" />
}
</div>
At the moment I have a drop down box which only displays a Suppliers Name with the value of the ID hidden behind it. I would also like to display the Suppliers account number next to the Supplier Name.
HTML:
#Html.DropDownListFor(
m => m.SupplierID,
new SelectList(Model.Suppliers, "SupplierID", "SupplierName"),
new { #id = "SuppNameDD", #class = "GRDropDown" }
)
Controller:
public ActionResult Index(string client) {
int clientID = clientRepo.GetClientIDByName(client);
DashboardViewModel model = new DashboardViewModel();
model.ClientID = clientID;
model.ClientName = client;
model.FinancialsAtAGlance = reportRepo.GetFinancialsAtAGlance(model.ClientID);
model.SupplierID = -1;
model.AccountNo = null;
model.Suppliers = supplierRepo.GetAllSuppliersByClient(clientID);
model.ReviewID = -1;
model.AccountNo = null;
model.Reviews = reviewRepo.GetAllReviewsByClientID(clientID);
return View(model);
}
ViewModel:
public class DashboardViewModel {
public int ClientID { get; set; }
public string ClientName { get; set; }
public IQueryable<FinancialsAtAGlanceModel> FinancialsAtAGlance { get; set; }
public Dictionary<string, Dictionary<string, decimal?>> Budgets { get; set; }
public class SelectReport {
public int ReportID { get; set; }
public string ReportType { get; set; }
public static IEnumerable<SelectReport> Reports = new List<SelectReport> {
new SelectReport {
ReportID = 1,
ReportType = "Claims By Supplier"
},
new SelectReport {
ReportID = 2,
ReportType = "Department breakdown"
},
new SelectReport {
ReportID = 3,
ReportType = "Reason Code breakdown"
},
new SelectReport {
ReportID = 4,
ReportType = "Monthly Debiting report"
}
};
}
public List<SelectReport> allReports { get; set; }
public int SupplierID { get; set; }
public IEnumerable<Supplier> Suppliers { get; set; }
public int ReviewID { get; set; }
public string AccountNo { get; set; }
public IEnumerable<Review> Reviews { get; set; }
}
How can add this is as the other value is a selected value and this is not what I want. It should be another datatext field.
If this display name is something that would be used multiple times, I would suggest adding a property to your Supplier class. Something like DisplayName:
public class Supplier
{
//...
public string SupplierName { get; set; }
public string AccountNumber { get; set; }
//...
public string DisplayName
{
get { return String.Format("{0} ({1})", SupplierName, AccountNumber); }
}
}
Then, you just need to change your drop down list to use DisplayName instead of SupplierName as the text field:
#Html.DropDownListFor(m => m.SupplierID, new SelectList(Model.Suppliers, "SupplierID", "DisplayName"), new { #id = "SuppNameDD", #class = "GRDropDown" })
EDIT:
There is another way to do this that can be done all in the view:
#Html.DropDownListFor(m => m.SupplierID, Model.Suppliers.Select(item => new SelectListItem
{
Value = item.SupplierID.ToString(),
Text = String.Format("{0} ({1})", item.SupplierName, item.AccountNumber.ToString()),
Selected = item.SupplierID == Model.SupplierID
}))
Probably you can achieve your desired output by 1.create a custom helper with with extension method which will return MvcHtmlString which will create your custom HTML for dropdown and call that method in your view.
Like Below
public static class CustomDropdown
{
public static string Dropdown(Priority priority)
{
StringBuilder sb=new StringBuilder ();
sb+="<Select id='drop'>";
for(int i=0;i<priority.name.length;i++)
{
sb+="<option id='dropop' value='"+priority.value[i]+"'title='"+priority.title[i]+"'>"+priority.name[i]+"</option>";
}
sb+="</select>";
return Convert.ToString(sb);
}
}
2.Bind the options of the given select with help of jquery like
var i=0;
$('.drpclass option').each(function(){
$(this).attr('title',Model.priority.title[i])
i++;
});
Just started messing around with MVC and have been trying to accomplish this by looking at this example:
http://forums.asp.net/t/1670552.aspx
I keep getting this error:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Line 9: #using (Html.BeginForm("Index","Home",FormMethod.Post, new{id = "ID"})){
Line 10: #Html.DropDownListFor(m=>m.id, new SelectList(Model.list, "id","name"),"selectThis")
Line 11: }
Here is the code:
Model classes (stupid names, I know):
These are in a console application used only to store models.
namespace Model
{
public class Model
{
public int id { get; set; }
public string name { get; set; }
}
public class List
{
public int id { get; set; }
public List<Model> list = new List<Model>();
}
public class subModel
{
public int id { get; set; }
public int modId { get; set; }
public string name { get; set; }
}
public class subList
{
public List<subModel> list = new List<subModel>();
}
}
Controller: (was populating subList.list and List.list with methods in the class, but decided to try it this way now, was getting the same error)
namespace DropboxTest.Controllers
{
public class HomeController : Controller
{
//
// GET: /Model/
public ActionResult Index()
{
LoadModel();
return View();
}
[ValidateInput(false)]
[AcceptVerbs("POST")]
public ActionResult Index([Bind(Exclude = "id")]Model.Model model)
{
var modId = Request["id"];
LoadModel();
LoadSubCategory(Convert.ToInt32(modId));
return View();
}
public void LoadModel()
{
Model.List listM = new Model.List();
listM.id = 0;
Model.Model mod1 = new Model.Model();
mod1.id = 1;
mod1.name = "me";
Model.Model mod2 = new Model.Model();
mod2.id = 2;
mod2.name = "me";
listM.list.Add(mod1);
listM.list.Add(mod2);
ViewBag.Model = listM;
}
public void LoadSubCategory(int id)
{
Model.subList subList = new Model.subList();
Model.subModel sub1 = new Model.subModel();
Model.subModel sub2 = new Model.subModel();
sub1.id = 1;
sub1.name = "notme";
sub1.modId = 1;
sub2.id = 1;
sub2.name = "notme";
sub2.modId = 1;
subList.list.Add(sub1);
subList.list.Add(sub2);
List<Model.subModel> sel = new List<Model.subModel>();
foreach (var item in subList.list)
{
if (item.modId == id)
{
sel.Add(item);
}
}
ViewBag.SubModel = sel;
}
}
}
View: (I have no idea if anything for subModel dropdown is working as I haven't even gotten to that part yet, but w/e.)
#model Model.List
#{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
#using (Html.BeginForm("Index","Home",FormMethod.Post, new{id = "ID"})){
#Html.DropDownListFor(m=>m.id, new SelectList(Model.list, "id","name"),"selectThis")
}
#if (ViewBag.SubModel != null)
{
#Html.DropDownList("SubModel",ViewBag.SubModel as SelectList, "select one")
}
It's probably something really stupid but I've been stuck for a couple of hours trying different things.
PS: This is just a test app. After I see how it is done I will be doing one with and SQL DB, using models in ConsoleApplications to retrieve and store data from the DB and display it in views, so any advice on that will be also appreciated.
A big thank you to all that have read up to here and have a nice day.
You never pass a model to the view in the controller, you just store in ViewBag.Model.
Try something as follows:
[ValidateInput(false)]
[AcceptVerbs("POST")]
public ActionResult Index([Bind(Exclude = "id")]Model.Model model)
{
var modId = Request["id"];
//get model
var model = LoadModel();
//pass it to the view
return View(model);
}
HI I am stuck in getting data that i need to display in kendo UI GRID , Initially I am able to see the button and textbox and grid as well but when i enter the value in textbox and then press the button i need to show that entered values in kendo UI GRID ...
When I run this application in google chrome it was giving empty grid,after enters the value and then press the submit button but when I run this one in IE8 it was giving error like this at starting stage itself....
Unhandled exception at line 238, column 37 in Function code
0x800a138f - Microsoft JScript runtime error: 'data.EmployeeDetails.EmployeeId' is null or not an object
and this is my model
public class TextBoxGrid
{
public string EnteredValue { get; set; }
public List<EmployeeDetails> employees;
}
public class ParentViewModel
{
public EmployeeDetails EmployeeDetails { get; set; }
public TextBoxGrid TextBoxGrid { get; set; }
}
public class EmployeeDetails
{
public string EmployeeId { get; set; }
public string ManagerId { get; set; }
}
this is my controller
public class EnterValuesGridController : Controller
{
private static List<EmployeeDetails> empdtls;
public ActionResult Index( ParentViewModel model)
{
var viewmodel = new ParentViewModel
{
TextBoxGrid = new TextBoxGrid { employees = GetEmployee().ToList() }
};
return View(viewmodel);
}
[HttpPost]
public ActionResult PostValues(TextBoxGrid model)
{
TempData["enteringValue"] = model.EnteredValue;
var viewmodel = new ParentViewModel
{
TextBoxGrid = new TextBoxGrid { employees = GetEmployee().ToList() }
};
//ParentViewModel p = new ParentViewModel();
//TextBoxGrid t = new TextBoxGrid();
//t.EnteredValue = "a";
//TempData["a1"] = t.EnteredValue;
//t.employees = GetEmployee().ToList();
//p.TextBoxGrid = t;
//return View("Index", p);
return View("Index", viewmodel);
}
public IEnumerable<EmployeeDetails> GetEmployee()
{
string enteredValueId =(string) TempData["enteringValue"];
string managerId = "M" +enteredValueId;
empdtls = new List<EmployeeDetails>();
EmployeeDetails em1 = new EmployeeDetails();
em1.EmployeeId = enteredValueId;
em1.ManagerId = managerId;
empdtls.Add(em1);
return empdtls.AsEnumerable();
}
public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
{
return Json(GetOrders().ToDataSourceResult(request));
}
private IEnumerable<EmployeeDetails> GetOrders()
{
return GetEmployee().AsEnumerable();
}
}
and this is my view
#model KendoPratapSampleMVCApp.Models.ParentViewModel
#{
ViewBag.Title = "Index";
}
#using (Html.BeginForm("PostValues", "EnterValuesGrid", FormMethod.Post))
{
#Html.TextBoxFor(m=>m.TextBoxGrid.EnteredValue)
<input type="submit" name="Submitbutton1" value="Submit1" />
#(Html.Kendo().Grid<KendoPratapSampleMVCApp.Models.ParentViewModel>()
.Name("grid")
.Columns(columns => {
columns.Bound(s=>s.EmployeeDetails.EmployeeId).Filterable(false).Width(100);
columns.Bound(s => s.EmployeeDetails.ManagerId).Filterable(false).Width(100);
})
.Filterable()
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action("Orders_Read", "EnterValuesGrid"))
)
)
}
I am not sure where I am doing wrong, Would you pls suggest any ideas on this one ..
Many thanks...., Do i need to do any changes in UI GRID I have tried changing the post values method ...but it didnot worked for me ...
UPDATE :
changed tempData to view Bag...
[HttpPost]
public ActionResult PostValues(ParentViewModel model)
{
ViewBag.item = model.TextBoxGrid.EnteredValue;
var viewmodel = new ParentViewModel
{
TextBoxGrid = new TextBoxGrid { employees = GetEmployee().ToList() }
};
//ParentViewModel p = new ParentViewModel();
//TextBoxGrid t = new TextBoxGrid();
//t.EnteredValue = "a";
//TempData["a1"] = t.EnteredValue;
//t.employees = GetEmployee().ToList();
//p.TextBoxGrid = t;
//return View("Index", p);
return View("Index", viewmodel);
}
public IEnumerable<EmployeeDetails> GetEmployee()
{
string enteredValueId = (string)ViewBag.item;
string managerId = "M" +enteredValueId;
empdtls = new List<EmployeeDetails>();
EmployeeDetails em1 = new EmployeeDetails();
em1.EmployeeId = enteredValueId;
em1.ManagerId = managerId;
empdtls.Add(em1);
return empdtls;
}
Hi pratap i just update your code,
Model
public class TextBoxGrid
{
public string EnteredValue { get; set; }
public List<EmployeeDetails> employees;
}
public class ParentViewModel
{
public EmployeeDetails EmployeeDetails { get; set; }
public TextBoxGrid TextBoxGrid { get; set; }
}
public class EmployeeDetails
{
public string EnteredValue { get; set; }
public string EmployeeId { get; set; }
public string ManagerId { get; set; }
}
View
#model TwoModelInSinglePageModel.EmployeeDetails
#{
ViewBag.Title = "Index";
}
<script src="~/Script/Jquery-1.8.1.min.js" type="text/javascript"></script>
<script src="~/Script/jquery-ui-1.8.20.min.js" type="text/javascript"></script>
<script src="#Url.Content("~/Script/kendo.all.min.js")" type="text/javascript"></script>
<script src="~/Script/kendo.web.min.js" type="text/javascript"></script>
<script src="~/Script/kendo.aspnetmvc.min.js" type="text/javascript"></script>
#using (Html.BeginForm("PostValues", "Test", FormMethod.Post))
{
#Html.TextBoxFor(m => m.EnteredValue)
<input type="submit" name="Submitbutton1" value="Submit1" />
#(Html.Kendo().Grid<TwoModelInSinglePageModel.EmployeeDetails>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(s => s.EmployeeId);
columns.Bound(s => s.ManagerId);
})
.Filterable()
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action("Orders_Read", "Test"))
)
)
}
Controller
private static List<EmployeeDetails> empdtls;
public ActionResult PostValues()
{
return View();
}
[HttpPost]
public ActionResult PostValues(EmployeeDetails model)
{
ViewBag.item = model.EnteredValue;
ParentViewModel viewmodels = new ParentViewModel
{
TextBoxGrid = new TextBoxGrid { employees = GetEmployee().ToList() }
};
ParentViewModel viewmodel = new ParentViewModel();
EmployeeDetails em1 = new EmployeeDetails();
for (int i = 0; i < viewmodels.TextBoxGrid.employees.Count(); i++)
{
em1.EmployeeId = viewmodels.TextBoxGrid.employees[i].EmployeeId;
em1.ManagerId = viewmodels.TextBoxGrid.employees[i].ManagerId;
viewmodel.EmployeeDetails = em1;
}
Session["EM1"] = em1;
return View("PostValues", em1);
}
public List<EmployeeDetails> GetEmployee()
{
string enteredValueId = (string)ViewBag.item;
string managerId = "M" + enteredValueId;
empdtls = new List<EmployeeDetails>();
EmployeeDetails em1 = new EmployeeDetails();
em1.EmployeeId = enteredValueId;
em1.ManagerId = managerId;
if (Session["EM1"] != null)
{
em1 = Session["EM1"] as EmployeeDetails;
empdtls.Add(em1);
Session["EM1"] = null;
}
else
{
empdtls.Add(em1);
}
return empdtls;
}
public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request, EmployeeDetails model)
{
return Json(GetEmployee().ToDataSourceResult(request));
}
OK, I read through your post again and you want to submit the form when click on the button actually. So, let's try to put the value in the session
Session["enteringValue"] = model.EnteredValue;
And you can retrieve it using
string enteredValueId = (string)(Session["enteringValue"]);