frankcollins3 / ASPIZZA

microsoft learning module
1 stars 0 forks source link

creating serverside functions in C#? [7:40am] #7

Closed frankcollins3 closed 1 year ago

frankcollins3 commented 1 year ago

attempting to do: razor .cshtml && C#

error: So issue #5 covers that this code cannot be changed once it's sent to client. @{ ViewData["Title"] = "Pizza Party"; TimeSpan timeInBusiness = DateTime.Now - new DateTime(2018, 8, 14);
string favoritePizza = "pepperoni"; } issue #6 covers that: // these won't access variables defined in the @{} 👎 pizzaText.textContent = "Everyone likes " + @favoritePizza 👎 pizzaText.textContent = everyone likes ${@favoritePizza} // this will work and serialize the JSON. 👍 pizzaText.textContent = "Everyone likes " + @Html.Raw(Json.Serialize(randomPizza)); // this will work

proposed approach: @ { } is it possible to make a function in here that can be sent over and invoked. It will grab that random value (hoping to make that function non-static, in that it can continually grab a changing random value)

another proposed approach: serialize the array and grab a random value from it.

possible improvements: // issue #7 is basically a possible improvement of issue #6 but needs its own space since its really a new issue/question about: serverside static string function instead of using static string array and JS function to return random value.

frankcollins3 commented 1 year ago

also mentioning, because this is possible, invoking the @Convert.ToInt32() and directly rendering HTML of return value..

The best pizza in town for @Convert.ToInt32(timeInBusiness.TotalDays) days!

👍 the proposed approach above could have some merit. [7:46am]

frankcollins3 commented 1 year ago

WOW: Screen Shot 2023-09-15 at 7 47 49 AM [7:48am]

frankcollins3 commented 1 year ago

👎 doesn't work Screen Shot 2023-09-15 at 7 53 20 AM

👍 works (hard-coded string value) Screen Shot 2023-09-15 at 7 52 52 AM [7:53am]

frankcollins3 commented 1 year ago

@functions { } // kind of funny would've found this out progressing through the microsoft modules. wanted to tinker 1st Screen Shot 2023-09-15 at 7 57 19 AM [7:58am]

frankcollins3 commented 1 year ago

@functions { } [8:14am]