Closed frankcollins3 closed 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]
WOW: [7:48am]
👎 doesn't work
👍 works (hard-coded string value) [7:53am]
@functions { } // kind of funny would've found this out progressing through the microsoft modules. wanted to tinker 1st [7:58am]
@functions { } [8:14am]
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 workproposed 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.