TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Deepak Awashti
NA
301
74.6k
how to create a proper view in controller passing the data
Aug 4 2016 3:12 AM
how to create a proper view in controller passing the data in view using model
please help me its urgent .
code :-
public async Task<ActionResult> Index()
{
// var model = new RootObject();
if (Request.HttpMethod == "POST")
{
string Origin = Request.Form["Origin"];
string Destination = Request.Form["Destination"];
string dateString = Convert.ToDateTime(Request.Form["Departure"]).ToString("yyyy-MM-dd");
string dateStringR = Convert.ToDateTime(Request.Form["Return"]).ToString("yyyy-MM-dd");
WebClient datawebclient = new WebClient();
string url = "https://" + "api.test.sabre.com/v1/shop/flights?origin=" + Origin + "&destination=" + Destination + "&departuredate=" + dateString + "&returndate=" + dateStringR + "&onlineitinerariesonly=N&limit=10&offset=1&eticketsonly=N&sortby=totalfare&order=asc&sortby2=departuretime&order2=asc&pointofsalecountry=US";
string data = string.Empty;
string AccessToken = "T1RLAQLHmr9Bsl3qBQiyJmYbAAjGU29q4RDUT9wV+XIfFPei6krNZto5AACgbtAZFC3fGLP5b+2AWt4EMH9trBd6lovskG1RKgBZFXbJWXZ3ejoF5V8kKouUGKPelL+WF52pzfRNMloDtR3/shpHbS+jF37TERm4LsvSBus3gkfs7jox3NjiClITbeII/G8vX17zPJfO+EwetlGKApl9Z2WiRqq/Cc+WFFw3E0K90z+KkbqISiGY1XQlieKyqrVwTwwFkcNLQ1xEZAeagg**";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + AccessToken);
data = await client.GetStringAsync(url);
}
var info = JsonConvert.DeserializeObject<RootObject>(data);
if (info != null)
{
List<PricedItinerary> firstName = info.PricedItineraries;
foreach (var value in firstName)
{
int seqNo = value.SequenceNumber;
var AirIT = value.AirItinerary;
}
ViewBag.data = firstName;
return View();
}
// ViewBag.data =data ;
}
return View();
}
}
}
model class:-
public class RootObject
{
public List<PricedItinerary> PricedItineraries { get; set; }
public string ReturnDateTime { get; set; }
public string DepartureDateTime { get; set; }
public string DestinationLocation { get; set; }
public string OriginLocation { get; set; }
public List<Link> Links { get; set; }
}
View Code:-
@model IEquatable< MvcApplication2.Models.RootObject>
@{
ViewBag.Title = "Index";
}
<form class="form-horizontal" method="post">
<fieldset>
<legend>Enter Details</legend>
<div class="form-group">
<label for="select" class="col-lg-2 control-label">Origin</label>
<div class="col-lg-10">
<select class="form-control" name="Origin" required>
<option></option>
<option value="JFK">John F. Kennedy International Airport</option>
<option value="LAX">Ministro Pistarini</option>
<option value="MIA">Miami International Airport</option>
</select>
</div>
</div>
<div class="form-group">
<label for="select" class="col-lg-2 control-label">Destination</label>
<div class="col-lg-10">
<select class="form-control" name="Destination" required>
<option></option>
<option value="JFK">John F. Kennedy International Airport</option>
<option value="LAX">Ministro Pistarini</option>
<option value="MIA">Miami International Airport</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-lg-2 control-label">Departure</label>
<div class="col-lg-10">
<input type="date" class="form-control" name="Departure" required>
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-lg-2 control-label">Return</label>
<div class="col-lg-10">
<input type="date" class="form-control" name="Return" required>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<input name="endpointName" type="hidden" value="Air Search" class="form-control">
<input name="methodName" type="hidden" value="InstaFlights Search" class="form-control">
<input name="httpMethod" type="hidden" value="GET" class="form-control">
<input name="methodUri" type="hidden" value="/v1/shop/flights" class="form-control">
<button type="reset" class="btn btn-default">Cancel</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
<h2>Url</h2>
@ViewBag.url
<hr />
<h2>Data</h2>
@ViewBag.data
Reply
Answers (
2
)
How to allow duplicate table in dataset?
Mail sending using web form , FROM my Domain Email account