Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. public static MvcHtmlString SendMailTo(this HtmlHelper helper, string emailAddress, string subject, string displayText)
  2. {
  3. var sb = string.Format("<a href="{0}{1}{2}" title="{1}">{3}</a>",
  4. CharEncode("mailto:"), CharEncode(emailAddress),CharEncode("?subject=" +subject), CharEncode(displayText));
  5.  
  6. return new MvcHtmlString(sb);
  7. }
  8.  
  9. public static string CharEncode(string value)
  10. {
  11. var enc = System.Text.Encoding.Default;
  12. var retval = "";
  13. for (var i = 0; i < value.Length; i++)
  14. {
  15. retval += "&#" + enc.GetBytes(new[] { Convert.ToChar(value.Substring(i, 1)) })[0] + ";";
  16. }
  17. return retval;
  18. }
  19.  
  20. <div class="form-group">
  21. @Html.LabelFor(m => m.ApplicationId, new { @class = "col-sm-3 control-label" })
  22. <div class="col-sm-8">
  23. @Html.TextBoxFor(m => m.ApplicationId, new {@class = "form-control"})
  24. </div>
  25. </div>
  26. <div class="form-group">
  27. <div class="col-sm-11" style="text-align:right">
  28. @Html.SendMailTo("info@test.com", "Password Request: ", "Request Password")
  29. <button type="submit" class="button">Sign in</button>
  30. </div>
  31. </div>
  32.  
  33. `$('.class of your textbox').val()' //will return a string
  34.  
  35. c.1 Place your partial view in a `div element`
  36. c.2 Make an `ajax` call from `jquery` to an action which returns your partial view filled with data
  37.  
  38. Example for c.2:
  39.  
  40. *AJAX*
  41.  
  42. $.ajax({
  43. type:"GET",
  44. data:{
  45. mail:$('.class of your textbox').val()
  46. },
  47. success: function(response){
  48. $(".class of your div").html(response.Html);
  49. }
  50. error: function(response){
  51. // whatever you want to do
  52. }
  53. });
  54.  
  55. *Controller Action*
  56.  
  57. public JsonResult(string mail)
  58. {
  59.  
  60. var model = new CustomModel(){ Mail=mail }; // custom class to your as model for your partial view
  61.  
  62. var html = RenderPartial(...) // method you can find in the link posted below
  63. return Json(
  64. {
  65. Html=html
  66. },JsonRequestBehavior.AllowGet)
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement