如何在数据库中插入页面的当前URL

时间:2019-03-27 07:39:39

标签: sql-server asp.net-mvc

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

1 个答案:

答案 0 :(得分:0)

您必须在数据库中有一列(如果未添加1个带有名称url的列),请说出url,它在Model类ip中也将可用(如果未添加具有名称url的属性)。您的方法dblayer.Add_data_pharma(ip)将完成其余的工作。

  

ip.url = Request.Url.AbsoluteUri;