【问题标题】:how to insert the current url of the page in the database如何在数据库中插入页面的当前url
【发布时间】:2019-03-27 07:39:39
【问题描述】:
if (ModelState.IsValid)
        {

            ip.patientname = fc["patientname"];
            ip.patientmail = fc["patientmail"];
            ip.patientcountry = fc["patientcountry"];
            ip.patientquery = fc["patientquery"];
            ip.SecurityCode = fc["SecurityCode"];

            string url = Request.Url.AbsoluteUri;




            dblayer.Add_data_pharma(ip);
            TempData["msg"] = "Inserted";

        }
        else
        {
            TempData["msg"] = "Not Inserted";
        }


        ModelState.Clear();
        return Redirect(Request.UrlReferrer.PathAndQuery);
    }

字符串 url = Request.Url.AbsoluteUri;

我想知道如何使用 Request.Url.AbsoluteUri 或任何方法在数据库中插入 url 名称。

public void Add_data_pharma(insert_askpharma_mar212019 ip)
        {
            SqlCommand com = new SqlCommand("insert_askpharma", con);
            com.CommandType = CommandType.StoredProcedure;
            com.Parameters.AddWithValue("@pharmaid", ip.pharmaid);
            com.Parameters.AddWithValue("@patientname", ip.patientname);
            com.Parameters.AddWithValue("@patientmail", ip.patientmail);
            com.Parameters.AddWithValue("@patientcountry", ip.patientcountry);
            com.Parameters.AddWithValue("@patientquery", ip.patientquery);
            com.Parameters.AddWithValue("@SecurityCode", ip.SecurityCode);
            com.Parameters.AddWithValue("@urlname", string.Empty);
            com.Parameters.AddWithValue("@ipaddress", string.Empty);
            con.Open();
            com.ExecuteNonQuery();
            con.Close();
        }

我想使用mvc将当前页面的url插入数据库中

<div id="myModal" class="modal fade" role="dialog">
                            <div class="modal-dialog">

                                <!-- Modal content-->
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal">&times;</button>

                                    </div>
                                    <div class="modal-body">
                                        <div class="row">
                                            <div class="col-sm-6">
                                                <h3 style="color:#669900">Personal Information</h3>
                                               @using (Html.BeginForm("AskOurPharmacist", "Basic", FormMethod.Post, new { @id = "kycFormTab5" }))
                                             {
                                                    <div class="form-group">
                                                        <label for="email">Name*</label>
                                                        <input type="text" class="form-control" id="patientname" name="patientname">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="pwd">Phone*</label>
                                                        <input type="text" class="form-control" id="" name="">
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="email">Email*</label>
                                                        <input type="email" class="form-control" id="patientmail" name="patientmail">
                                                    </div>
                                                    <div class="form-group">

                                                        <input type="hidden" class="form-control" id="patientcountry" name="patientcountry">
                                                    </div>
                                                    <div class="form-group">

                                                        <input type="hidden" class="form-control" id="patientquery" name="patientquery">
                                                    </div>
                                                    <div class="form-group">

                                                        <input type="hidden" class="form-control" id="SecurityCode" name="SecurityCode">
                                                    </div>
                                                    <div class="form-group">
                                                        <input type="hidden" class="form-control" id="urlname" name="urlname">
                                                    </div>
                                                    <button type="submit" class="btn btn-success">Email me When in Stock</button>
                                             }
                                            </div>
                                            <div class="col-sm-6">
                                                <div class="rbox">
                                                    <h4 class=" text-center"><strong>Why shop with Us?</strong></h4>
                                                    <ul class="list-unstyled">
                                                        <li><i class="fa fa-heart">&nbsp;</i>Trusted for Quality and Price</li>
                                                        <li><i class="fa fa-heart">&nbsp;</i>80-90% Savings - Lowest Prices</li>
                                                        <li><i class="fa fa-heart">&nbsp;</i>Free Shipping WorldWide*</li>
                                                        <li><i class="fa fa-heart">&nbsp;</i>360° Round View of Products</li>
                                                        <li><i class="fa fa-heart">&nbsp;</i>No Hidden Cost</li>
                                                        <li><i class="fa fa-heart">&nbsp;</i>Saving Rewards, Referral Discounts</li>
                                                        <li><i class="fa fa-heart">&nbsp;</i>Quality-Assured Medications</li>
                                                        <li class="text-right">*T&C Apply</li>
</ul>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

这是我的观点,在一种方法中,我已经在这个表单中插入了两个表单,我只想在数据库中插入 url 都在同一个表中

this is my database

【问题讨论】:

  • 如何传递字符串 url = Request.Url.AbsoluteUri;在数据库中
  • Request.Url.AbsoluteUri 是字符串,将其保存在新列中您的问题到底是什么?
  • 我想在提交表单时将当前页面的url插入数据库中,请帮助我,我的代码在上面,数据库在那里
  • ip.URL= Request.Url.AbsoluteUri; ?????????
  • 它不工作\

标签: sql-server asp.net-mvc


【解决方案1】:

您必须在数据库中有一个列(如果不添加名称为 url 的 1),比如说 url,该列在模型类 ip 中也可用(如果不添加名称为 url 的属性)。您的方法 dblayer.Add_data_pharma(ip) 将完成其余的工作。

ip.url = Request.Url.AbsoluteUri;

【讨论】:

  • 它没有插入到数据库中,我想传递任何可见的东西
  • 你想在数据库中插入 url 吗?还是只是将其传递给视图?
  • 我想在数据库中插入url
  • 你可以使用,viewbag/viewdata/tempdata: e.g: ViewBag.Url = Request.Url.AbsoluteUri;在视图中,您可以获得如下值: string s = View.Url;
  • 我想将它直接插入到视图部分我没有通过任何这个我的模型 public string urlname { get;放; }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-14
  • 2011-06-13
  • 1970-01-01
相关资源
最近更新 更多