I am wondering if there is a way to edit a MVC 4 model then reload the view with the new model from jQuery. The basics of what I am trying to do is I have a page that has weeks of dates and text boxes after each date. This page is for a time card site. The model contains the days of the week and the name of the days for that date. What I am want to modify is the dates in the model so if a user is on this week and realizes they forgot to enter there time for last week they can click a button that takes the to enter time for the last week. I have function to get the dates and the days of the week just not sure how to edit the model and reload it.
The site controllers in C# code samples or any idea would be helpful.
You should look into communicating with your server using jQuery/AJAX. Serialize you model into JSON, modify it in your controller and send it back. You can then update your view with the new data.
Related
I have a asp.net chart which shows some attendance of month.
I have a dropdown which shows the month name. The user will select the month from the dropdown and click on a button.
On this button click, I want to call ActionResult mettod, which will fetch the data from a database of selected month and bind the data to chart(dotnet.highcharts).
I want to know if I can bind data to an asp.net chart with specific values.
Can anyone please let me know how to do this?
Your method would probably return JsonResult in that case. Once you receive that json on the client side (through ajax request e.g.) you would submit it to Highcharts series property.
I'm currently working on a large project which has a Timesheet class containing a list of TimesheetEntries. There is an edit page for this that looks like:
<!-- Other timesheet properties -->
#Html.EditorFor(model => model.TimesheetEntries)
This works great, I get a row for each timesheet entry. When I save the timesheet (POST to the server) a custom model binder strips out empty rows before passing a Timesheet to the controller, in other words the Timesheet can contain fewer rows than the POST data.
If there is a validation error I redisplay the edit page and this is where the problem arises.
If model.TimesheetEntries contains n records Html.EditorFor() reproduces the first n rows from the POST data (including the empty rows) rather than creating HTML for the data I pass it! This means I lose a number of rows at the bottom of the table which is clearly unwanted.
Can anyone explain why this is happening or even better tell me how to get EditorFor to work as I expect?
Here's a picture to describe the process:
You may want to take a look at the answer provided in this post Asp:net MVC 3: #Html.EditorFor a subcollection of my model in a template? It may help.
Turns out Html.EditorFor looks in ModelState before using the values you pass it... So to get it to pick up the values I passed it I needed to clear the relevant ones out of ModelState first, ugh.
This question/answer covers it in more detail.
Please help me out here I have about 1 day experience of C# ASP.NET web dev and I am stuck on something really simple. I am much more experienced in PHP and jQuery.
What I need to do:
Create a GridView and display data from MSSQL DB [done]
Add buttons to each row to enable direct editing of values in two columns [done]
Each row represents a list of equipment that the user can edit/save, and I need to add an extra "Edit Details" button to each row [done]
Upon clicking the "Edit Details" button, I need to pass the id of that list to a new page where user can edit and save the list
I have added a HyperLinkField for the row id to be passed on, in Visual Studio I have tried to config it so that the value can be read on the receiving page with Request.Params["xxxx"] but it is not working.
In PHP I would just create a POST <form> with hidden <input> values and obtain the value by $_POST["xxxx"]
However it seems that all this fancy ASP.NET and Visual Studio DataSource pointer/reference and config things are making things more complicated than I wished.
I greatly appreciate any help given, or any resources that will be helpful for me to transfer my skills in PHP over to ASP.NET with C#.
If you are passing it through query string use
string value = Request.QueryString["id"].ToString();;
If you are passing it through post use
string value = Request.Forms["id"].ToString();
I have a date picker control that I use for a data collection application. It is using MvvM data binding. When going through a list of dates (see fig1) it will populate the date picker correctly. Whenever I hit new, the date pickers are nulled out. When I pull up the popup, it selects the month and year from the previous date that was set to. (fig 2) Is there anyway to default the pop up show the current month in the current year?
Note : I would like to keep the selected date to null on a new entry to force some validation.
Fig 1
Fig 2
The following image is to show what happens when I set the DisplayDateStart.
(original answer was horribly wrong, sorry about that)
Okay, lets try this again.
Have you tried setting the fallback to today's date?
SelectedDate="{Binding TehDate, FallbackValue={x:Static sys:DateTime.Now}}"
My goal here is to store a list of dates selected in a calandar to a database. The problem with most calendar controls that exist, for asp.net, is I can't get the date that was unselected with multiselect enabled. I can get a list but that is really it. I have decided not to use these because of this.
If I wanted to create my own event using the jQuery calendar below how would I go about doing this? The event would capture the day clicked, if it was unselected or selected, etc. I would use this to add/remove the dates from a collection. It is almost like how the other calendars work except for the remove part. The dates removed would be in it's own list so I know what dates to remove from the database once 'save' is clicked. I hope this is enough information.
http://www.eyecon.ro/datepicker/#about
Using Visual Studio 2005/.NET 2.0. c#
if you wanted to save multiple dates (list), you could:
-use jquery to create 1 input box for selecting date and another list area the selected dates
-on post back, have the server code check the list area for all the selected dates
if you wanted to save only one date, you could:
-use jquery to create 1 input box for selecting date
-on post back, the server code check for the that input box
hope that helps.