I have a view and some the value of the model class of the view is not displayed in the view but the value has to be get in the controller when i click submit button of the view
My view BreakDownReport file code is given below. When I click submit button of the view , the following variable should be passed to the controller
var report = {};
report.LogYear = "@Model.LogYear"
report.LogMonth = "@Model.LogMonth"
report.EmployeeIds = "@Model.EmployeeIds"
How can I pass the above value from view to controller Please help
Like many of your posts, the shared code is not complete and the problem description is not relate to the code. This makes it very difficult to understand the problem. On top of incomplete code the code shown makes little logical sense. For example,
the following code populates a JavaScript object but there is not indication what problem this approach solves. Are you planning to submit an AJAX POST?
Can you explain the purpose of the HTML table? Is the table related to the JavaScript in some way? Are you trying to filter tabular data?
Can you explain the back button, which is the only button on the page. Are you trying to go back to a previous state?
I recommend that you take a step back and come up with clear requirements. Then explain the requirements to the community. Include code that proves you are making a good faith attempt to solve this problem.
I meant to pass the value of the variable report.logyear,report.logmonth, report.employeeids to the post method of the view when I click the <submit> button from the view. The value is stored in the variable but I dodnt know how to pass from view
to controller post method.
With Thanks
Pol
[HttpPost]publicIActionResultBreakDownReport(BreakDownEntrymodel log) // Here I want to bring the value from the view the variable report{ return view()
}
You could use ajax to pass the value to the controller.And if you want to use @Model.property,you need to modify your view.Here is a simple workaround like below:
1.Model:
public class BreakDownLogEntryModel
{
[Key]
public int DepotNo { get; set; }
public string Employee { get; set; }
public string Customer { get; set; }
public string DateCarried { get; set; }
public string DateInvoiced { get; set; }
public string LogYear { get; set; }
public string LogMonth { get; set; }
public int EmployeeIds { get; set; }
}
public async Task<IActionResult> Details(int? id)
{
var breakDownLogEntryModel = new BreakDownLogEntryModel() { DepotNo=1,Employee = "as",Customer = "ad", DateCarried ="2017-8-9", DateInvoiced ="2014-8-9", LogYear ="2017",LogMonth="8", EmployeeIds =1};
return View(breakDownLogEntryModel);
}
[HttpPost]
public IActionResult BreakDownReport(BreakDownLogEntryModel report)
{
//more logic...
return View();
}
4.Result:
Best Regards,
Rena
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
414 Points
1341 Posts
how can I pass the value from the view to the controller post method when I click the submit butt...
Sep 22, 2019 11:01 AM|polachan|LINK
I have a view and some the value of the model class of the view is not displayed in the view but the value has to be get in the controller when i click submit button of the view
My view BreakDownReport file code is given below. When I click submit button of the view , the following variable should be passed to the controller
var report = {};
report.LogYear = "@Model.LogYear"
report.LogMonth = "@Model.LogMonth"
report.EmployeeIds = "@Model.EmployeeIds"
How can I pass the above value from view to controller Please help
My controller post method is given below
All-Star
53711 Points
24040 Posts
Re: how can I pass the value from the view to the controller post method when I click the submit...
Sep 22, 2019 12:43 PM|mgebhard|LINK
Like many of your posts, the shared code is not complete and the problem description is not relate to the code. This makes it very difficult to understand the problem. On top of incomplete code the code shown makes little logical sense. For example, the following code populates a JavaScript object but there is not indication what problem this approach solves. Are you planning to submit an AJAX POST?
Can you explain the purpose of the HTML table? Is the table related to the JavaScript in some way? Are you trying to filter tabular data?
Can you explain the back button, which is the only button on the page. Are you trying to go back to a previous state?
I recommend that you take a step back and come up with clear requirements. Then explain the requirements to the community. Include code that proves you are making a good faith attempt to solve this problem.
Member
414 Points
1341 Posts
Re: how can I pass the value from the view to the controller post method when I click the submit...
Sep 22, 2019 04:33 PM|polachan|LINK
I meant to pass the value of the variable report.logyear,report.logmonth, report.employeeids to the post method of the view when I click the <submit> button from the view. The value is stored in the variable but I dodnt know how to pass from view to controller post method.
With Thanks
Pol
Contributor
2720 Points
874 Posts
Re: how can I pass the value from the view to the controller post method when I click the submit...
Sep 23, 2019 03:23 AM|Rena Ni|LINK
Hi polachan,
You could use ajax to pass the value to the controller.And if you want to use @Model.property,you need to modify your view.Here is a simple workaround like below:
1.Model:
2.View(Details.cshtml):
3.Controller:
4.Result:
Best Regards,
Rena
Member
414 Points
1341 Posts
Re: how can I pass the value from the view to the controller post method when I click the submit...
Sep 23, 2019 06:42 PM|polachan|LINK
Many Thanks