Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ********************FontPickerController***********************
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using MIS324Assignments.Models;
- namespace MIS324Assignments.Controllers
- {
- public class FontPickerController : Controller
- {
- // GET: FontPicker
- [HttpGet]
- public ActionResult Index()
- {
- FontPickerModel fp = new FontPickerModel();
- ViewBag.imageTags = GenerateImageTags(fp.Message);
- return View(fp);
- }
- [HttpGet]
- public ActionResult Fonts()
- {
- FontPickerModel fp = new FontPickerModel();
- ViewBag.imageTags = GenerateImageTags(fp.Message, fp.FontId);
- return View(fp);
- }
- [HttpPost]
- public ActionResult Index(FontPickerModel fp)
- {
- Response.Write("Method Post");
- if (ModelState.IsValid)
- {
- ViewBag.imageTags = GenerateImageTags(fp.Message);
- }
- return View(fp);
- }
- [HttpPost]
- public ActionResult Fonts(FontPickerModel fp)
- {
- Response.Write("Method Post");
- if (ModelState.IsValid)
- {
- ViewBag.imageTags = GenerateImageTags(fp.Message, fp.FontId);
- }
- return View(fp);
- }
- string GenerateImageTags(string Message, string FontId = "")
- {
- //build a string of image tags
- string imageTags = "";
- for (int i = 0; i < Message.Length; i++)
- {
- string character = Message.Substring(i, 1);
- if (character != " ")
- imageTags += GetTag(character, FontId);
- else
- imageTags += "<br />";
- }
- return imageTags;
- }
- private string GetTag(string character, string FontId)
- {
- string url = "<img src='http://yorktown.cbe.wwu.edu/sandvig/images/alphabet/";
- if (FontId == "ChunkRed")
- {
- return url + "chunk/red/" + character + "9.jpg' />";
- }
- else if (FontId == "DecoBlue")
- {
- return url + "deco/blue/" + character + "1.gif' />";
- }
- else if (FontId == "Animals")
- {
- return url + "animals/" + character + "4.gif' />";
- }
- else if (FontId == "ElegantRed")
- {
- return url + "elegant/red/4" + character + ".gif' />";
- }
- else if (FontId == "Funky")
- {
- return url + "funky/" + character + "3.jpg' />";
- }
- else
- {
- return url + "punch/black/" + character + "7.gif' />";
- }
- }
- }
- }
- ********************************fonts.cshtml*************************************************(this one was a work in progress, namely with the dropdownlistfor HTML helper near the bottom)****************************************************
- @model MIS324Assignments.Models.FontPickerModel
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width" />
- <title>Fonts</title>
- </head>
- <body>
- @Scripts.Render("~/bundles/jquery")
- @Scripts.Render("~/bundles/jqueryval")
- @using (Html.BeginForm())
- {
- @Html.AntiForgeryToken()
- <div class="form-horizontal">
- <h4>FontPickerModel</h4>
- <hr />
- @Html.ValidationSummary(true, "", new { @class = "text-danger" })
- <div class="form-group">
- @Html.LabelFor(model => model.Message, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => model.Message, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.Message, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => model.FontId, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.DropDownListFor(
- model => model.FontId,
- new SelectList(MIS324Assignments.ViewModels.FontPickerViewModel.FontPickerViewModel.FontList, "FontID",
- "FontName",
- new { htmlAttributes = new { @class = "form-control" } }))
- @Html.ValidationMessageFor(model => model.FontId, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <input type="submit" value="Create" class="btn btn-default" />
- </div>
- </div>
- </div>
- }
- <div>
- @Html.ActionLink("Back to List", "Index")
- </div>
- </body>
- </html>
- ****************************************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement