I want to call an action I've got in my controller class with a Html.ActionLink
from my index
page but I'm getting an error and can't understand why.
Can anyone help me?
The Test
action in HomeController.cs
is the action I want to call.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Microsoft.Exchange.WebServices.Data;
namespace ExchangeRazor.Controllers
{
public class HomeController : Controller
{
public ActionResult Index ()
{
var mvcName = typeof(Controller).Assembly.GetName ();
var isMono = Type.GetType ("Mono.Runtime") != null;
ViewData ["Version"] = mvcName.Version.Major + "." + mvcName.Version.Minor;
ViewData ["Runtime"] = isMono ? "Mono" : ".NET";
return View ();
}
public ActionResult Test()
{
ExchangeService service = new ExchangeService ();
//CREDENTIALS!//
service.Credentials = new WebCredentials ("*****@****.com", "******");
service.Url = new Uri ("https://outlook.office365.com/EWS/Exchange.asmx");
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
EmailMessage email = new EmailMessage (service);
email.ToRecipients.Add ("********");
email.Subject = "MacHallo";
email.Body = new MessageBody ("Melding fra mac exchange webservices API");
email.Send ();
return RedirectToAction("Index");
}
}
}
Index.cshtml:
<h2>Welcome to ASP.NET MVC @ViewData["Version"] on @ViewData["Runtime"]!</h2>
<button>@Html.ActionLink("Send", "Test")</button>
Edit:
System.MissingMethodException Method not found: 'System.Web.Routing.RouteCollection.get_AppendTrailingSlash'.
Description: HTTP 500.Error processing request. Details: Non-web exception. Exception origin (name of application or object): System.Web.Mvc.