小编dc9*_*922的帖子

如何从MVC 5应用程序发送电子邮件

我有一个客户需要填写的表格.提交表单后,我想将表单的索引视图(名字,姓氏,电话号码等)中的基本信息发送到电子邮件.我目前正在使用GoDaddy作为我的托管网站.这有关系,还是我可以直接从我的MVC应用程序发送电子邮件?我的模型,视图,控制器有以下内容.我以前从未这样做过,我真的不确定如何去做.

模型:

public class Application
{
    public int Id { get; set; }

    [DisplayName("Marital Status")]
    public bool? MaritalStatus { get; set; }


    [Required]
    [DisplayName("First Name")]
    public string FirstName { get; set; }

    [DisplayName("Middle Initial")]
    public string MiddleInitial { get; set; }
     [Required]
    [DisplayName("Last Name")]
    public string LastName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

控制器:

public ActionResult Index()
{
        return View();
}

// POST: Applications/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc sendmail

15
推荐指数
3
解决办法
7万
查看次数

ViewBag和HtmlHelper错误:"无法找到编译动态表达式所需的一种或多种类型.您是否缺少程序集引用?"

ViewBag错误:"无法找到编译动态表达式所需的一种或多种类型.您是否缺少程序集引用?"

所有HTML Helper方法都包含错误:"无法从使用中推断出方法的类型参数.请尝试明确指定类型参数."

花了最后两天挖掘与此错误相关的其他帖子,这是我尝试过的:

  • 修复Visual Studio
  • 重新安装Visual Studio
  • 确保我引用了Microsoft.CSharp和System.Core
  • 添加到global.asax:ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new CustomRazorViewEngine());
  • 将Microsoft.CSharp Copy Local的参考值从false更改为True
  • 今天我安装了更新RC 3
  • 检查GAC版本(仅包含版本4.0.0.0)
  • 卸载/重新安装最新版本的.NET框架

这是我的观点Web.Config:

<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
        <add namespace="WebApplication14" />
      </namespaces> …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc visual-studio-2013 razorengine

8
推荐指数
2
解决办法
5582
查看次数

带有实体框架的MVC下拉列表

我首先使用实体​​框架代码创建了一个MVC项目.我的模型只是一个收集信息的表单.

public class Application
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string MiddleInitial { get; set; }
    public string LastName { get; set; }
    public int SSN { get; set; }
    public DateTime DOB { get; set; }
    public string Street { get; set; }
    public string City { get; set; }
    public string State {get; set; }
    public string Zip { get; set; }
    public int HomePhone { get; set; …
Run Code Online (Sandbox Code Playgroud)

model-view-controller asp.net-mvc entity-framework

6
推荐指数
2
解决办法
2万
查看次数

DbComparisonExpression需要具有可比类型的参数

我是新手使用Linq并尝试创建一个搜索按图表编号搜索并在新的操作视图中显示结果.运行代码时,我得到错误"DbComparisonExpression需要具有可比类型的参数".我相信这与搜索类型有关,字符串和图表编号是int,但我不知道如何解决问题.任何帮助将不胜感激!

控制器:

public ActionResult Index(string searchTerm = null)
{
    var model =
        db.Patient
        .Where(r => searchTerm == null || r.ChartNumber.Equals(searchTerm))
                .Select(r => new NewListModel
                {
                    ChartNumber = r.ChartNumber,
                    FirstName = r.FirstName,
                    LastName = r.LastName,
                }
                );
    return View(model);
}
Run Code Online (Sandbox Code Playgroud)

模型:

public class NewListModel
{
    public int ChartNumber { get; set; }

    public string FirstName { get; set; }
    public string LastName { get; set; }

}
Run Code Online (Sandbox Code Playgroud)

视图:

@model IEnumerable<Project.Models.NewListModel>
@{
    ViewBag.Title = "Home Page";
}

<form method="get">
    <input type="search" name="searchTerm" …
Run Code Online (Sandbox Code Playgroud)

c# linq-to-sql

5
推荐指数
1
解决办法
1万
查看次数

@ Html.Dropdownlist列表未保存到数据库

在下面的例子中,我试图将Id从Asp.Net Identity,"aspnetusers"表"Id"列保存到我的"Application"表中.填写"fullname"的下拉列表,但在我提交申请时不会保存到我的"申请"表.我需要在提交应用程序后将aspnetusers表中的"Id"保存到我的"应用程序"表中.非常感谢帮助!

控制器:

private ApplicationDbContext db = new ApplicationDbContext();

public ActionResult Index()
{
    ViewBag.FullNameList = new SelectList(db.Users,"Id","FullName");
    return View();
}

// POST: Applications/Create
[ValidateAntiForgeryToken]
public ActionResult Index([Bind(Include = "Id,FullName, FirstName,MiddleInitial,LastName,")]   Application application)
{
    if (ModelState.IsValid)
    {
        ViewBag.FullNameList = new SelectList(db.Users, "Id", "FullName", application.ApplicationUser);
        db.Applications.Add(application);

        db.SaveChanges();

        return RedirectToAction("Thanks");
    }
}
Run Code Online (Sandbox Code Playgroud)

视图:

<p>
      @Html.DropDownListFor(m => m.FullName, (SelectList)ViewBag.FullNameList, "Select Loan Officer")
</p>
Run Code Online (Sandbox Code Playgroud)

模型:

public class Application
{
    public int ApplicationId { get; set; }

    [Required]
    [DisplayName("First Name")]
    public string FirstName { get; set; …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc

1
推荐指数
1
解决办法
771
查看次数