【问题标题】:How to post x-editable input value on razor page如何在剃须刀页面上发布 x-editable 输入值
【发布时间】:2022-01-05 07:12:29
【问题描述】:

我想要点击提交按钮时, 发送表单到发布方法。 谢谢你的帮助。
html代码

                                <form method="post" class="form-horizontal editor-horizontal">
                                    <div class="form-group">
                                        <div class="col-sm-9">
                                            <a href="#" id="name" data-type="text"
                                               data-pk="1" data-placeholder="Required"
                                               data-title="نام خود را وارد کنید">@Model.Information.Doctor.Name</a>
                                        </div>
                                        <label class="col-sm-3 control-label">نام</label>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-9">
                                            <a data-pk="1" data-placeholder="Required" data-placement="left"
                                               data-title="نام خانوادگی خود را وارد کنید " data-type="text"
                                               href="#" id="family" >@Model.Information.Doctor.Family</a>
                                        </div>
                                        <label class="col-sm-3 control-label">نام خانوادگی </label>
                                    </div>
                           
                                    <button type="submit" class="btn btn-primary"  >تایید</button>/>
                             </form>

这是我的方法帖

        public IActionResult OnPost(EditDoctorViewModel command)
        {
           var user= _service.EditDoctor(command);

           return Page();

        }

【问题讨论】:

  • 为什么在你的观点中使用&lt;a&gt;...&lt;/a&gt;?如果你想将值传递给 Post 方法,你应该使用&lt;input&gt;&lt;/input&gt;@Qudrat Ihsas

标签: javascript .net asp.net-core razor-pages x-editable


【解决方案1】:

如果你想发送表单到 post 方法,你应该在你的视图中使用input,这是我的代码:

型号

public class EditDoctorViewModel
    {
        public Information information { get; set; }
    }

public class Information
    {
        public Doctor Doctor { get; set; }
    }

public class Doctor
    {
        public string Name { get; set; }
        public string Family { get; set; }
    }

查看

<form method="post" class="form-horizontal editor-horizontal">
     <div class="form-group">
       <label class="col-sm-3 control-label" >نام</label>
       <input type="text" asp-for="command.information.Doctor.Name" />
     </div>
     <div class="form-group">                             
         <label class="col-sm-3 control-label" >نام خانوادگی </label>
         <input type="text" asp-for="command.information.Doctor.Family" />
     </div>
     <button type="submit" class="btn btn-primary">تایید</button>
</form>

控制器

        public EditDoctorViewModel command { get; set; }
        public Information Information { get; set; }
 

        public IActionResult OnPost([FromForm]EditDoctorViewModel command)
        {
            //var user = _service.EditDoctor(command);

            return Page();

        }

那么你就可以在 Post Method 中接收价值了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-13
    • 1970-01-01
    • 2021-10-11
    • 2021-10-27
    • 2020-04-15
    • 2021-03-01
    • 2022-01-16
    • 2020-09-08
    相关资源
    最近更新 更多