繁体   English   中英

当我发布到操作时出现 dotnet 5 MVC 404 错误

[英]dotnet 5 MVC 404 error when I post to action

我有一个页面应该提交数据以进行患者评估。 提交评估的页面很好。 它基于 ViewModel。 这是视图模型:

public class SPEPatientEvalVM
    {
        public int Id { get; set; }
        public int ApptId { get; set; }
        public int ActivityID { get; set; }
        public int VendorID { get; set; }
        public int PatientID { get; set; }
        [Required(ErrorMessage ="A selection is required.")]
        public int OverallRating { get; set; }
        [Required(ErrorMessage = "A selection is required.")]
        public int AppearProfessComp { get; set; }
        [Required(ErrorMessage = "A selection is required.")]
        public int EffGatheredInfo { get; set; }
        [Required(ErrorMessage = "A selection is required.")]
        public int ListenActively { get; set; }
        [Required(ErrorMessage = "A selection is required.")]
        public int EstabPersRapport { get; set; }
        [Required(ErrorMessage = "A selection is required.")]
        public int AppropExploreMyFeelings { get; set; }
        [Required(ErrorMessage = "A selection is required.")]
        public int AddressedMyFeelings { get; set; }
        [Required(ErrorMessage = "A selection is required.")]
        public int MetMyNeeds { get; set; }
        public string PatientComments { get; set; } = String.Empty;
        public DateTime DateSubmitted { get; set; }
    }

这是使用 IMapper 映射和反向映射到 model 的。

无论如何,这是我的 controller 代码:

[HttpGet("[controller]/[action]/{IDAppt}/{ActivityID}/{VendorID}/{PatientID}")]
public async Task<IActionResult> AddSPEPatientEval(int IDAppt, int ActivityID, int VendorID, int PatientID)
{
    var patientChoice = GetPatientChoiceList();
    patientChoice[0].Selected = true;
    ViewBag.PatientChoice = patientChoice;

    var evalParams = await _speRepo.GetOpenPatientEval(IDAppt);

    ViewBag.Patient = evalParams.SPEPatient;

    var speEval = new SPEPatientEvalVM
    {
        ApptId = IDAppt,
        ActivityID = ActivityID,
        VendorID = VendorID,
        PatientID = PatientID
    };

    return View(speEval);
}

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> AddSPEPatientEval(SPEPatientEvalVM model)
{
    var patientChoice = GetPatientChoiceList();
    patientChoice[0].Selected = true;
    ViewBag.PatientChoice = patientChoice;

    model.DateSubmitted = DateTime.Now;

    if (ModelState.IsValid)
    {
        var spePatientEval = _mapper.Map<SPEPatientEval>(model);

        var success = await _speRepo.AddSPEPatientEval(spePatientEval);
        if (!success)
        {
            return View(model);
        }
        return View("Index");
    }
    return View(model);
}

这就是 AddSPEPatientEval.cshtml 形式的全部内容

@model SPEPatientEvalVM

@{
    ViewData["Title"] = "AddSPEPatientEval";
}

<div class="col-md-8 m-auto">
    <h1 class="text-center">Patient SPE Evaluation</h1>
    <hr />
</div>

<div class="col-md-8 m-auto">
    <div class="row">
        <div class="col-md-12">
            <form asp-controller="SPE" asp-action="AddSPEPatientEval" method="post">
                <div asp-validation-summary="ModelOnly" class="text-danger"></div>
                <input type="hidden" asp-for="ApptId" />
                <input type="hidden" asp-for="ActivityID" />
                <input type="hidden" asp-for="VendorID" />
                <input type="hidden" asp-for="PatientID" />
                <input type="hidden" asp-for="DateSubmitted" value="@String.Format("{0:MM/dd/yyyy}", DateTime.Now)" />
                <div class="row">
                    <div class="col-md-8 m-auto">
                        <div class="form-group">
                            <label asp-for="OverallRating" class="control-label">As @ViewBag.Patient, rate your overall level of satisfaction with this encounter.</label>
                            <select asp-for="OverallRating" class="form-control"
                                    asp-items="@(new SelectList(ViewBag.PatientChoice, "Value", "Text"))"></select>
                            <span asp-validation-for="OverallRating" class="text-danger"></span>
                        </div>
                        <br />
                        <hr />
                    </div>
                </div>
                <br />
                <div class="row">
                    <div class="col-md-8 m-auto">
                        <div class="form-group">
                            <label asp-for="AppearProfessComp" class="control-label">Appeared professional competent - seemed to know what s/he was
                                doing; inspired my comfidence; appeared to have my interests at heart.
                            </b></label>
                            <select asp-for="AppearProfessComp" class="form-control"
                                    asp-items="@(new SelectList(ViewBag.PatientChoice, "Value", "Text"))"></select>
                            <span asp-validation-for="AppearProfessComp" class="text-danger"></span>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-8 m-auto">
                        <div class="form-group">
                            <label asp-for="EffGatheredInfo" class="control-label">Effectively gathered information - collected information in a way that
                                seemed organized; began with several open-ended questions and progressed through interview using a balanced ratio of open- 
                                to closed-ended questions; summarized periodically.
                            </label>
                            <select asp-for="EffGatheredInfo" class="form-control"
                                    asp-items="@(new SelectList(ViewBag.PatientChoice, "Value", "Text"))"></select>
                            <span asp-validation-for="EffGatheredInfo" class="text-danger"></span>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-8 m-auto">
                        <div class="form-group">
                            <label asp-for="ListenActively" class="control-label">Listened actively - paid attention to both my verbal and non-verbal 
                                cues; used facial expressions/body language to express encouragement; avoided interruptions; asked questions to make sure 
                                s/he understood what I said.
                            </label>
                            <select asp-for="ListenActively" class="form-control"
                                    asp-items="@(new SelectList(ViewBag.PatientChoice, "Value", "Text"))"></select>
                            <span asp-validation-for="ListenActively" class="text-danger"></span>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-8 m-auto">
                        <div class="form-group">
                            <label class="control-label">Established personal rapport - introduced self warmly; verbally/non-verbally showed interest 
                                in me as a person, not just my condition; avoided technical jargon.
                            </label>
                            <select asp-for="EstabPersRapport" class="form-control"
                                    asp-items="@(new SelectList(ViewBag.PatientChoice, "Value", "Text"))"></select>
                            <span asp-validation-for="EstabPersRapport" class="text-danger"></span>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-8 m-auto">
                        <div class="form-group">
                            <label asp-for="AppropExploreMyFeelings" class="control-label">Appropriately explored my perspective - encouraged me to 
                                identify everything that I needed to say.
                            </label>
                            <select asp-for="AppropExploreMyFeelings" class="form-control"
                                    asp-items="@(new SelectList(ViewBag.PatientChoice, "Value", "Text"))"></select>
                            <span asp-validation-for="AppropExploreMyFeelings" class="text-danger"></span>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-8 m-auto">
                        <div class="form-group">
                            <label asp-for="AddressedMyFeelings" class="control-label">Addressed my feelings - acknowledged and demonstrated interest in my 
                                expressed and/orunexpressed feelings and experience.
                            </label>
                            <select asp-for="AddressedMyFeelings" class="form-control"
                                    asp-items="@(new SelectList(ViewBag.PatientChoice, "Value", "Text"))"></select>
                            <span asp-validation-for="AddressedMyFeelings" class="text-danger"></span>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-8 m-auto">
                        <div class="form-group">
                            <label asp-for="MetMyNeeds" class="control-label">Met my needs - worked toward a plan which addressed both the diagnosis and 
                                my concerns about my illness.
                            </label>
                            <select asp-for="MetMyNeeds" class="form-control"
                                    asp-items="@(new SelectList(ViewBag.PatientChoice, "Value", "Text"))"></select>
                            <span asp-validation-for="MetMyNeeds" class="text-danger"></span>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-8 m-auto">
                        <div class="form-group">
                            <label asp-for="PatientComments" class="control-label"></label>
                            <textarea asp-for="PatientComments" class="form-control"
                                      placeholder="Please add any additional comments you would like to express about this examination."></textarea>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-8 m-auto">
                        <div class="form-group">
                            <input type="submit" value="Submit" class="btn btn-primary" />
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-8 m-auto">
        <div class="text-center">
            <a asp-action="Index">Back to List</a>
        </div>
    </div>
</div>

@section Scripts {
    @{
        await Html.RenderPartialAsync("_ValidationScriptsPartial");
    }
    }

完成表格并输入所有必填字段后,如果我点击“提交”按钮,我会得到:

找不到此localhost页面,找不到Z2567A5EC9705EB7AC2C98403E06189DZ地址:Z5E056C4B6A71C500A71110B50D807BADE5Z:// LOCALSPEPEPEPETATIREVEREVENM:50011110D807BADE629595959595959595959595959565659565656565656565.ADSSPEPETATEREVEREVER:

我想念什么? 我确信这是在普通网站上的东西。 我只是看了太久,找不到发生了什么。

我试过什么...我觉得一切。 我尝试向 HttpPost 语句添加路由。 我已经尝试确保所有 model 字段都不是 null。 我不知道还能尝试什么。

提前感谢您的帮助。

[FromRoute]添加到操作参数中:

[HttpGet("[controller]/[action]/{IDAppt}/{ActivityID}/{VendorID}/{PatientID}")]
public async Task<IActionResult> AddSPEPatientEval([FromRoute]int IDAppt, [FromRoute] int ActivityID, [FromRoute] int VendorID, [FromRoute] int PatientID)

您还应该将HttpGet更改为HttpPost

您的POST路由应与GET路由匹配: [HttpPost("[controller]/[action]/{IDAppt}/{ActivityID}/{VendorID}/{PatientID}")]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM