1

I have a entity called WorkOrder which gets assigned to an Employee.

I want send an email notification when the workorder has been asigned. This can happen on my MVC Create or Edit Action (POST).

The problem i have is i have to do checks to see if the value has changed in the Edit to determine if i should send an email.

Is there a better place to call the SendEmail Function, like in the Entity Model itself?

4

1 回答 1

2

如果您正在谈论从视图发布,您可以在加载视图时创建现有值并将其绑定到表单中的隐藏字段。然后,在 POST 到您的操作中,您可以检查字段中的值是否与隐藏字段中的值不同。

视图示例:

@using (Html.BeginForm("MyAction", "MyController")
{
    @Html.HiddenFor(m => m.CurrentValue)
    @Html.TextBoxFor(m => m.Value)
    <input type="submit" value="submit" />
}

操作 GET 示例

public ActionResult MyAction()
{
    var viewModel = GetModelFromSomeWhere();
    viewModel.CurrentValue = viewModel.Value;
    return this.View(viewModel);
}

动作 POST 示例

[HttpPost]
public ActionResult MyAction(ViewModel model)
{
    if (model.Value != model.CurrentValue)
    {
        // It has changed! Send that email!
    }
}
于 2013-05-23T20:00:45.903 回答