How to update additional dependent fields when dropdown selection changes










0















I have written several custom validation classes that permit comparing pairs of dates to see if they are valid, e.g. end date on or after start date. See mvc4 data annotation compare two dates. These work well when used within a single model. But I don’t know how to use them in a view model of parent and child entities to be used for creating and editing the child entities.



Let the parent entity be an Academic Calendar and the child entity be a Course. I am trying to create or edit a Course. In addition to requiring the Course start and end dates to be valid, I need to be able to check that the Course start date is on or after the Calendar start date and that the Course end date is on or before the Calendar end date. So I need to compare dates across two data models.



I created a view model that includes both the course data and calendar data, e.g. CourseId, CourseName, CourseStartDate, CourseEndDate plus CalendarId, CalendarName, CalendarStartDate, and CalendarEndDate. In the view, I can create a dropdown for Calendars with value and text fields corresponding to id and name, e.g. 1 and Fall 2018. My problem is that I need to be able to show the corresponding Calendar Start and End dates corresponding to the selected calendar. With Web Forms, I could add extra hidden columns to a dropdown, but I don’t know how to do that with MVC and Razor. I’d like the Calendar dates to be in read-only textboxes, so they can be checked by my comparison validation classes before attempting to insert a new ─ or update an existing ─ course. I need these Calendar date values to change when the selection changes in the dropdown.










share|improve this question






















  • The context of a ValidationAttribute is the class itself. It has no knowledge of its parent entity. Since you are using a view model then you can add the CalendarStartDate etc in the CourseViewModel so that you get client and server side validation using a custom ValidationAttribute. As far as changing the dates based on a selected option, you need to use javascript to handle client side events.

    – user3559349
    Nov 16 '18 at 8:32











  • As a side note, the Q/A you linked to does not give client side validation - for that you need to implement IClientValidatable - refer The Complete Guide To Validation In ASP.NET MVC 3 - Part 2

    – user3559349
    Nov 16 '18 at 8:34















0















I have written several custom validation classes that permit comparing pairs of dates to see if they are valid, e.g. end date on or after start date. See mvc4 data annotation compare two dates. These work well when used within a single model. But I don’t know how to use them in a view model of parent and child entities to be used for creating and editing the child entities.



Let the parent entity be an Academic Calendar and the child entity be a Course. I am trying to create or edit a Course. In addition to requiring the Course start and end dates to be valid, I need to be able to check that the Course start date is on or after the Calendar start date and that the Course end date is on or before the Calendar end date. So I need to compare dates across two data models.



I created a view model that includes both the course data and calendar data, e.g. CourseId, CourseName, CourseStartDate, CourseEndDate plus CalendarId, CalendarName, CalendarStartDate, and CalendarEndDate. In the view, I can create a dropdown for Calendars with value and text fields corresponding to id and name, e.g. 1 and Fall 2018. My problem is that I need to be able to show the corresponding Calendar Start and End dates corresponding to the selected calendar. With Web Forms, I could add extra hidden columns to a dropdown, but I don’t know how to do that with MVC and Razor. I’d like the Calendar dates to be in read-only textboxes, so they can be checked by my comparison validation classes before attempting to insert a new ─ or update an existing ─ course. I need these Calendar date values to change when the selection changes in the dropdown.










share|improve this question






















  • The context of a ValidationAttribute is the class itself. It has no knowledge of its parent entity. Since you are using a view model then you can add the CalendarStartDate etc in the CourseViewModel so that you get client and server side validation using a custom ValidationAttribute. As far as changing the dates based on a selected option, you need to use javascript to handle client side events.

    – user3559349
    Nov 16 '18 at 8:32











  • As a side note, the Q/A you linked to does not give client side validation - for that you need to implement IClientValidatable - refer The Complete Guide To Validation In ASP.NET MVC 3 - Part 2

    – user3559349
    Nov 16 '18 at 8:34













0












0








0








I have written several custom validation classes that permit comparing pairs of dates to see if they are valid, e.g. end date on or after start date. See mvc4 data annotation compare two dates. These work well when used within a single model. But I don’t know how to use them in a view model of parent and child entities to be used for creating and editing the child entities.



Let the parent entity be an Academic Calendar and the child entity be a Course. I am trying to create or edit a Course. In addition to requiring the Course start and end dates to be valid, I need to be able to check that the Course start date is on or after the Calendar start date and that the Course end date is on or before the Calendar end date. So I need to compare dates across two data models.



I created a view model that includes both the course data and calendar data, e.g. CourseId, CourseName, CourseStartDate, CourseEndDate plus CalendarId, CalendarName, CalendarStartDate, and CalendarEndDate. In the view, I can create a dropdown for Calendars with value and text fields corresponding to id and name, e.g. 1 and Fall 2018. My problem is that I need to be able to show the corresponding Calendar Start and End dates corresponding to the selected calendar. With Web Forms, I could add extra hidden columns to a dropdown, but I don’t know how to do that with MVC and Razor. I’d like the Calendar dates to be in read-only textboxes, so they can be checked by my comparison validation classes before attempting to insert a new ─ or update an existing ─ course. I need these Calendar date values to change when the selection changes in the dropdown.










share|improve this question














I have written several custom validation classes that permit comparing pairs of dates to see if they are valid, e.g. end date on or after start date. See mvc4 data annotation compare two dates. These work well when used within a single model. But I don’t know how to use them in a view model of parent and child entities to be used for creating and editing the child entities.



Let the parent entity be an Academic Calendar and the child entity be a Course. I am trying to create or edit a Course. In addition to requiring the Course start and end dates to be valid, I need to be able to check that the Course start date is on or after the Calendar start date and that the Course end date is on or before the Calendar end date. So I need to compare dates across two data models.



I created a view model that includes both the course data and calendar data, e.g. CourseId, CourseName, CourseStartDate, CourseEndDate plus CalendarId, CalendarName, CalendarStartDate, and CalendarEndDate. In the view, I can create a dropdown for Calendars with value and text fields corresponding to id and name, e.g. 1 and Fall 2018. My problem is that I need to be able to show the corresponding Calendar Start and End dates corresponding to the selected calendar. With Web Forms, I could add extra hidden columns to a dropdown, but I don’t know how to do that with MVC and Razor. I’d like the Calendar dates to be in read-only textboxes, so they can be checked by my comparison validation classes before attempting to insert a new ─ or update an existing ─ course. I need these Calendar date values to change when the selection changes in the dropdown.







razor model-view-controller dependencies dropdown selectionchanged






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 1:16









Jeffrey RoughgardenJeffrey Roughgarden

349210




349210












  • The context of a ValidationAttribute is the class itself. It has no knowledge of its parent entity. Since you are using a view model then you can add the CalendarStartDate etc in the CourseViewModel so that you get client and server side validation using a custom ValidationAttribute. As far as changing the dates based on a selected option, you need to use javascript to handle client side events.

    – user3559349
    Nov 16 '18 at 8:32











  • As a side note, the Q/A you linked to does not give client side validation - for that you need to implement IClientValidatable - refer The Complete Guide To Validation In ASP.NET MVC 3 - Part 2

    – user3559349
    Nov 16 '18 at 8:34

















  • The context of a ValidationAttribute is the class itself. It has no knowledge of its parent entity. Since you are using a view model then you can add the CalendarStartDate etc in the CourseViewModel so that you get client and server side validation using a custom ValidationAttribute. As far as changing the dates based on a selected option, you need to use javascript to handle client side events.

    – user3559349
    Nov 16 '18 at 8:32











  • As a side note, the Q/A you linked to does not give client side validation - for that you need to implement IClientValidatable - refer The Complete Guide To Validation In ASP.NET MVC 3 - Part 2

    – user3559349
    Nov 16 '18 at 8:34
















The context of a ValidationAttribute is the class itself. It has no knowledge of its parent entity. Since you are using a view model then you can add the CalendarStartDate etc in the CourseViewModel so that you get client and server side validation using a custom ValidationAttribute. As far as changing the dates based on a selected option, you need to use javascript to handle client side events.

– user3559349
Nov 16 '18 at 8:32





The context of a ValidationAttribute is the class itself. It has no knowledge of its parent entity. Since you are using a view model then you can add the CalendarStartDate etc in the CourseViewModel so that you get client and server side validation using a custom ValidationAttribute. As far as changing the dates based on a selected option, you need to use javascript to handle client side events.

– user3559349
Nov 16 '18 at 8:32













As a side note, the Q/A you linked to does not give client side validation - for that you need to implement IClientValidatable - refer The Complete Guide To Validation In ASP.NET MVC 3 - Part 2

– user3559349
Nov 16 '18 at 8:34





As a side note, the Q/A you linked to does not give client side validation - for that you need to implement IClientValidatable - refer The Complete Guide To Validation In ASP.NET MVC 3 - Part 2

– user3559349
Nov 16 '18 at 8:34












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330108%2fhow-to-update-additional-dependent-fields-when-dropdown-selection-changes%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330108%2fhow-to-update-additional-dependent-fields-when-dropdown-selection-changes%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線