Это отличная возможность начать больше узнавать о переменном объеме! По сути, выбор не является глобальной переменной, и когда вы устанавливаете его значение в DisplayInfo()
, это значение фактически не передается обратно в main (). Вместо этого рассмотрим использование return
для отправки ввода пользователя обратно в функцию.
Вот ваш код с парой изменений для исправления бесконечного цикла:
...
while selection.upper() != "X":
if selection == 'C':
CalculateCost()
elif selection == 'D':
selection = DisplayInfo()
elif selection == 'X':
print('\nThanks for choosing Box and Go!')
# Declare the function that shows the shipping rates
def DisplayInfo():
print('==================================')
print('SHIPPING COST INFORMATION')
print('==================================\n')
print('All packages are flat rate shipping\n')
print('Flat Rate Envelope\t $6.70')
print('Small Flat Rate Box\t $7.20')
print('Medium Flat Rate Box\t $13.65')
print('Large Flat Rate Box\t $18.90\n')
# Allow the user to return to the main menu
return str(input('Press enter to return to main menu: ').upper())
Я также рекомендовал бы потратить некоторое время на изучение стека вызовов (т. Е. Глубины вызываемых функций программа). Когда вы вызываете main()
внутри DisplayInfo()
, вы фактически запускаете функцию снова через рекурсию, потому что она уже выполняется вне этого контекста. Хотя предел стека (как бы общеизвестное «переполнение») довольно высок, теоретически пользователь, продолжающий вводить «D», в конечном итоге приведет к ошибке вашей программы.
When you use this:
<a href="javascript:document.forms[0].submit()">
...you should be aware that it's not the same as
<input type="submit" />
It doesn't raise the onsubmit event, and MVC's AJAX eventhandler is not called.
To confirm this is the issue, add
<input type="submit" />
inside the form and try it out.
Finally, just call onsubmit() from your link
<a href="#" onclick="document.forms[0].onsubmit()">
RenderPartial принимает имя действия, а не имя пользовательского элемента управления, поэтому замените «IngredientsListControl» на «UpdateStep2», имя вашего действия.
Might be worth ensuring that you have correctly referenced the ajaxmvc and jquery scripts in your page (master page). If these are incorrect a new page will be displayed instead of the correct output in the target div.