0

I am trying to pass IP address to my view using ViewData but it isn't displaying correctly. Below is my coding for label:

@Html.Label(ViewData["CREATED_LOC"].ToString(), new { @class = "form-control", @disabled = "disabled" })

I inspected in my model, the data fetched is in string "10.200.4.7" but in my view it only displays 7. May i know what is the problem?

derloopkat
  • 6,232
  • 16
  • 38
  • 45

1 Answers1

0

You can use ViewBag... ViewBag using in c# controller:

ViewBag.IpAddress = Request.UserHostAddress;

after then u can use in view like this(display:none for your choice):

<span id="spnIpAddress" style="display:none">@ViewBag.IpAddress</span>

if you can use this ip address in ajax request. u can use like this:

_ipAddress: $('#spnIpAddress').text(),