Im new to ASP.net MVC and I use the DevExpress-MVC extensions to build a small application, a time registration for employees, that uses a DataGrid.
My Problem is the following one:
The user is able to enter a abbreviation of his name, submitting this to the controller should call a query to my DB and show his responding Employee-ID.
I got my DataViewModel to pass my Model to the view, now I thought binding it to the textbox and retrieving the data back from the ViewModel would do it, but it does not.
My Code looks like that:
ViewModel
public class MyErfassungViewModel
{
public MyErfassung erfassung;
public String personalnummer;
public String personalkuerzel;
public List<String> dim1;
public List<String> dim2;
public List<String> dim3;
public List<String> dim4;
public List<String> dim5;
public MyErfassungViewModel(MyErfassung myerfassung)
{
this.erfassung = myerfassung;
}
}
View
@model DevExpressMvcApplication.Models.ViewModel.MyErfassungViewModel
<div class ="Personalnummer">
@using (Html.BeginForm("getNummer","MyErfassung"))
{
<label>Personalkürzel</label>
@Html.DevExpress().TextBox(settings =>
{
settings.Name = "TextBoxPersonalkürzel";
}).Bind(Model.personalkuerzel).GetHtml()
<label>Personalnummer</label>
@Html.DevExpress().TextBox(settings =>
{
settings.Name = "TextBoxPersonalnummer";
settings.ReadOnly = true;
}).Bind(Model.personalnummer).GetHtml()
@Html.DevExpress().Button(settings =>
{
settings.Name = "TextBoxKuerzel";
settings.Text = "Holen";
settings.UseSubmitBehavior = true;
}).GetHtml()
<br>
}
</div>
Controller
//
// GET: /MyErfassung/
public ActionResult Index()
{
viewModel.personalkuerzel = "sese";
return View(viewModel);
}
[HttpPost]
public ActionResult getNummer()
{
String kurz = Convert.ToString(Request["TextBoxKuerzel"]);
String nr = Convert.ToString(Request["TextBoxPersonalnummer"]);
String nummer = dbRepo.getPersonalnummerByKuerzel(viewModel.personalkuerzel);
viewModel.personalnummer = nummer;
return View(viewModel);
}
Like you are able to see I tried some possible ways to receive the user input and send a DB-Request to get a number. But either the request or the viewmodel are containing more than a null reference.
But simply said I am not able to pass users input from my form back to the controller.